[kernel] Re-design thread blocking
In preparation for the new mailbox IPC model, blocking threads needed an overhaul. The `wait_on_*` and `wake_on_*` methods are gone, and the `block()` and `wake()` calls on threads now pass a value between the waker and the blocked thread. As part of this change, the concept of signals on the base kobject class was removed, along with the queue of blocked threads waiting on any given object. Signals are now exclusively the domain of the event object type, and the new wait_queue utility class helps manage waiting threads when an object does actually need this functionality. In some cases (eg, logger) an event object is used instead of the lower-level wait_queue. Since this change has a lot of ramifications, this large commit includes the following additional changes: - The j6_object_wait, j6_object_wait_many, and j6_thread_pause syscalls have been removed. - The j6_event_clear syscall has been removed - events are "cleared" by reading them now. A new j6_event_wait syscall has been added to read events. - The generic close() method on kobject has been removed. - The on_no_handles() method on kobject now deletes the object by default, and needs to be overridden by classes that should not be. - The j6_system_bind_irq syscall now takes an event handle, as well as a signal that the IRQ should set on the event. IRQs will cause a waiting thread to be woken with the appropriate bit set. - Threads waking due to timeout is simplified to just having a wake_timeout() accessor that returns a timestamp. - The new wait_queue uses util::deque, which caused the disovery of two bugs in the deque implementation: empty deques could still have a single array allocated and thus return true for empty(), and new arrays getting allocated were not being zeroed first. - Exposed a new erase() method on util::map that takes a node pointer instead of a key, skipping lookup.
This commit is contained in:
@@ -9,43 +9,38 @@
|
||||
#include <j6/syscalls.h>
|
||||
#include <j6/types.h>
|
||||
|
||||
j6_handle_t __handle_sys;
|
||||
j6_handle_t __handle_self;
|
||||
|
||||
namespace {
|
||||
constexpr size_t __static_arr_size = 4;
|
||||
j6_handle_t __handle_array[__static_arr_size];
|
||||
|
||||
static j6_status_t
|
||||
load_handles()
|
||||
{
|
||||
size_t count = __static_arr_size;
|
||||
j6_handle_t *handles = __handle_array;
|
||||
j6_status_t s = j6_handle_list(handles, &count);
|
||||
|
||||
if (s != j6_err_insufficient && s != j6_status_ok)
|
||||
return s;
|
||||
|
||||
if (count > __static_arr_size)
|
||||
count = __static_arr_size;
|
||||
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
uint8_t type = (handles[i] >> 56);
|
||||
if (type == j6_object_type_system && __handle_sys == j6_handle_invalid)
|
||||
__handle_sys = handles[i];
|
||||
else if (type == j6_object_type_process && __handle_self == j6_handle_invalid)
|
||||
__handle_self = handles[i];
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
constexpr size_t static_arr_size = 8;
|
||||
j6_handle_t handle_array[static_arr_size];
|
||||
} // namespace
|
||||
|
||||
j6_handle_t
|
||||
j6_find_first_handle(j6_object_type obj_type)
|
||||
{
|
||||
size_t count = static_arr_size;
|
||||
j6_handle_t *handles = handle_array;
|
||||
j6_status_t s = j6_handle_list(handles, &count);
|
||||
|
||||
if (s != j6_err_insufficient && s != j6_status_ok)
|
||||
return j6_handle_invalid;
|
||||
|
||||
if (count > static_arr_size)
|
||||
count = static_arr_size;
|
||||
|
||||
for (size_t i = 0; i < count; ++i) {
|
||||
uint8_t type = (handles[i] >> 56);
|
||||
if (type == obj_type) return handles[i];
|
||||
}
|
||||
|
||||
return j6_handle_invalid;
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
__init_libj6(uint64_t *rsp)
|
||||
{
|
||||
__handle_sys = __handle_self = j6_handle_invalid;
|
||||
load_handles();
|
||||
__handle_self = j6_find_first_handle(j6_object_type_process);
|
||||
}
|
||||
|
||||
#endif // __j6kernel
|
||||
|
||||
@@ -12,7 +12,6 @@ j6 = module("j6",
|
||||
"j6/errors.h",
|
||||
"j6/flags.h",
|
||||
"j6/init.h",
|
||||
"j6/signals.h",
|
||||
"j6/syscalls.h.cog",
|
||||
"j6/sysconf.h.cog",
|
||||
"j6/types.h",
|
||||
|
||||
@@ -1,37 +1,16 @@
|
||||
#pragma once
|
||||
/// \file init.h
|
||||
/// Types used in process and thread initialization
|
||||
/// Process initialization utility functions
|
||||
|
||||
#include <stdint.h>
|
||||
#include <j6/types.h>
|
||||
|
||||
enum j6_init_type { // `value` is a:
|
||||
j6_init_handle_self, // Handle to the system
|
||||
j6_init_handle_other, // Handle to this process
|
||||
j6_init_desc_framebuffer // Pointer to a j6_init_framebuffer descriptor
|
||||
};
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct j6_typed_handle {
|
||||
enum j6_object_type type;
|
||||
j6_handle_t handle;
|
||||
};
|
||||
/// Find the first handle of the given type held by this process
|
||||
j6_handle_t j6_find_first_handle(j6_object_type obj_type);
|
||||
|
||||
struct j6_init_value {
|
||||
enum j6_init_type type;
|
||||
union {
|
||||
struct j6_typed_handle handle;
|
||||
void *data;
|
||||
};
|
||||
};
|
||||
|
||||
/// Structure defining a framebuffer.
|
||||
/// `flags` has the following bits:
|
||||
/// 0-3: Pixel layout. 0000: rgb8, 0001: bgr8
|
||||
struct j6_init_framebuffer {
|
||||
uintptr_t addr;
|
||||
size_t size;
|
||||
uint32_t vertical;
|
||||
uint32_t horizontal;
|
||||
uint32_t scanline;
|
||||
uint32_t flags;
|
||||
};
|
||||
#ifdef __cplusplus
|
||||
} // extern "C"
|
||||
#endif
|
||||
|
||||
@@ -1,22 +0,0 @@
|
||||
#pragma once
|
||||
/// \file signals.h
|
||||
/// Collection of constants for the j6_signal_t type
|
||||
|
||||
// Signals 56-63 are common to all types
|
||||
#define j6_signal_no_handles (1ull << 56)
|
||||
#define j6_signal_closed (1ull << 57)
|
||||
#define j6_signal_global_mask 0xff00000000000000
|
||||
|
||||
// Signals 0-55 are defined per object type
|
||||
|
||||
// System signals
|
||||
#define j6_signal_system_has_log (1ull << 0)
|
||||
|
||||
// Channel signals
|
||||
#define j6_signal_channel_can_send (1ull << 0)
|
||||
#define j6_signal_channel_can_recv (1ull << 1)
|
||||
|
||||
// Endpoint signals
|
||||
#define j6_signal_endpoint_can_send (1ull << 0)
|
||||
#define j6_signal_endpoint_can_recv (1ull << 1)
|
||||
|
||||
Reference in New Issue
Block a user