mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
[kernel] Add object_signal system call
Add a system call to assert signals on a given object, only within the range of user-settable signals. Also made object_wait return immediately if any of the given signals are already set.
This commit is contained in:
@@ -13,6 +13,7 @@ extern "C" {
|
||||
j6_status_t system_log(const char *msg);
|
||||
|
||||
j6_status_t object_wait(j6_handle_t obj, j6_signal_t sig, j6_signal_t *out);
|
||||
j6_status_t object_signal(j6_handle_t obj, j6_signal_t sig);
|
||||
|
||||
j6_status_t process_koid(j6_koid_t *koid);
|
||||
|
||||
@@ -34,7 +35,13 @@ thread_proc()
|
||||
{
|
||||
system_log("sub thread starting");
|
||||
|
||||
j6_status_t result = channel_send(chan, sizeof(message), (void*)message);
|
||||
j6_status_t result = object_signal(chan, j6_signal_user0);
|
||||
if (result != j6_status_ok)
|
||||
thread_exit(result);
|
||||
|
||||
system_log("sub thread signaled user0");
|
||||
|
||||
result = channel_send(chan, sizeof(message), (void*)message);
|
||||
if (result != j6_status_ok)
|
||||
thread_exit(result);
|
||||
|
||||
@@ -65,6 +72,14 @@ main(int argc, const char **argv)
|
||||
if (result != j6_status_ok)
|
||||
return result;
|
||||
|
||||
system_log("main thread waiting on user0");
|
||||
|
||||
result = object_wait(chan, j6_signal_user0, &out);
|
||||
if (result != j6_status_ok)
|
||||
return result;
|
||||
|
||||
system_log("main thread waiting on can_recv");
|
||||
|
||||
result = object_wait(chan, j6_signal_channel_can_recv, &out);
|
||||
if (result != j6_status_ok)
|
||||
return result;
|
||||
|
||||
@@ -24,6 +24,7 @@ section .text
|
||||
|
||||
SYSCALL system_log, 0x00
|
||||
SYSCALL object_wait, 0x09
|
||||
SYSCALL object_signal, 0x0a
|
||||
SYSCALL process_koid, 0x10
|
||||
SYSCALL thread_koid, 0x18
|
||||
SYSCALL thread_create, 0x19
|
||||
|
||||
@@ -35,3 +35,5 @@
|
||||
#define j6_signal_user13 (1ull << 61)
|
||||
#define j6_signal_user14 (1ull << 62)
|
||||
#define j6_signal_user15 (1ull << 63)
|
||||
|
||||
#define j6_signal_user_mask (0xffffull << 48)
|
||||
|
||||
@@ -60,6 +60,9 @@ public:
|
||||
/// \arg s The set of signals to check
|
||||
inline bool check_signal(j6_signal_t s) const { return (m_signals & s) == s; }
|
||||
|
||||
/// Get the current object signal state
|
||||
inline j6_signal_t signals() const { return m_signals; }
|
||||
|
||||
/// Increment the handle refcount
|
||||
inline void handle_retain() { ++m_handle_count; }
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ SYSCALL(0x00, system_log, const char *)
|
||||
SYSCALL(0x01, system_noop, void)
|
||||
|
||||
SYSCALL(0x09, object_wait, j6_handle_t, j6_signal_t, j6_signal_t *)
|
||||
SYSCALL(0x0a, object_signal, j6_handle_t, j6_signal_t)
|
||||
|
||||
SYSCALL(0x10, process_koid, j6_koid_t *)
|
||||
SYSCALL(0x11, process_exit, int64_t)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "j6/errors.h"
|
||||
#include "j6/signals.h"
|
||||
#include "j6/types.h"
|
||||
|
||||
#include "log.h"
|
||||
@@ -19,6 +20,12 @@ object_wait(j6_handle_t handle, j6_signal_t mask, j6_signal_t *sigs)
|
||||
if (!obj)
|
||||
return j6_err_invalid_arg;
|
||||
|
||||
j6_signal_t current = obj->signals();
|
||||
if ((current & mask) != 0) {
|
||||
*sigs = current;
|
||||
return j6_status_ok;
|
||||
}
|
||||
|
||||
obj->add_blocked_thread(th);
|
||||
th->wait_on_signals(obj, mask);
|
||||
s.schedule();
|
||||
@@ -30,4 +37,22 @@ object_wait(j6_handle_t handle, j6_signal_t mask, j6_signal_t *sigs)
|
||||
return result;
|
||||
}
|
||||
|
||||
j6_status_t
|
||||
object_signal(j6_handle_t handle, j6_signal_t signals)
|
||||
{
|
||||
if ((signals & j6_signal_user_mask) != signals)
|
||||
return j6_err_invalid_arg;
|
||||
|
||||
scheduler &s = scheduler::get();
|
||||
thread *th = thread::from_tcb(s.current());
|
||||
process &p = th->parent();
|
||||
|
||||
kobject *obj = p.lookup_handle(handle);
|
||||
if (!obj)
|
||||
return j6_err_invalid_arg;
|
||||
|
||||
obj->assert_signal(signals);
|
||||
return j6_status_ok;
|
||||
}
|
||||
|
||||
} // namespace syscalls
|
||||
|
||||
Reference in New Issue
Block a user