mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 00:14:32 -08:00
[kernel] Add thead kobject class
Add the thread kernel API object and move the scheduler to use threads instead of processes for scheduling and task switching.
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
#include "j6/types.h"
|
||||
#include "kutil/vector.h"
|
||||
|
||||
class thread;
|
||||
|
||||
/// Base type for all user-interactable kernel objects
|
||||
class kobject
|
||||
{
|
||||
@@ -39,6 +41,9 @@ public:
|
||||
/// \returns The object type for the koid
|
||||
static type koid_type(j6_koid_t koid);
|
||||
|
||||
/// Get this object's koid
|
||||
inline j6_koid_t koid() const { return m_koid; }
|
||||
|
||||
/// Set the given signals active on this object
|
||||
/// \arg s The set of signals to assert
|
||||
void assert_signal(j6_signal_t s);
|
||||
@@ -47,31 +52,6 @@ public:
|
||||
/// \arg s The set of signals to deassert
|
||||
void deassert_signal(j6_signal_t s);
|
||||
|
||||
class observer
|
||||
{
|
||||
public:
|
||||
/// Callback for when signals change.
|
||||
/// \arg obj The object triggering the callback
|
||||
/// \arg s The current state of obj's signals
|
||||
/// \arg ds Which signals caused the callback
|
||||
/// \arg result Status code for this notification
|
||||
/// \returns True if this object wants to keep watching signals
|
||||
virtual bool on_signals_changed(
|
||||
kobject *obj,
|
||||
j6_signal_t s,
|
||||
j6_signal_t ds,
|
||||
j6_status_t result) = 0;
|
||||
};
|
||||
|
||||
/// Register a signal observer
|
||||
/// \arg object The observer
|
||||
/// \arg s The signals the object wants notifiations for
|
||||
void register_signal_observer(observer *object, j6_signal_t s);
|
||||
|
||||
/// Deegister a signal observer
|
||||
/// \arg object The observer
|
||||
void deregister_signal_observer(observer *object);
|
||||
|
||||
/// Increment the handle refcount
|
||||
inline void handle_retain() { ++m_handle_count; }
|
||||
|
||||
@@ -80,31 +60,30 @@ public:
|
||||
if (--m_handle_count == 0) on_no_handles();
|
||||
}
|
||||
|
||||
/// Add the given thread to the list of threads waiting on this object.
|
||||
inline void add_blocked_thread(thread *t) { m_blocked_threads.append(t); }
|
||||
|
||||
/// Remove the given thread from the list of threads waiting on this object.
|
||||
inline void remove_blocked_thread(thread *t) { m_blocked_threads.remove_swap(t); }
|
||||
|
||||
protected:
|
||||
/// Interface for subclasses to handle when all handles are closed. Subclasses
|
||||
/// should either call the base version, or assert j6_signal_no_handles.
|
||||
virtual void on_no_handles();
|
||||
|
||||
private:
|
||||
kobject() = delete;
|
||||
kobject(const kobject &other) = delete;
|
||||
kobject(const kobject &&other) = delete;
|
||||
|
||||
/// Notifiy observers of this object
|
||||
/// \arg mask The signals that triggered this call. If 0, notify all observers.
|
||||
/// \arg result The result to pass to the observers
|
||||
void notify_signal_observers(j6_signal_t mask, j6_status_t result = j6_status_ok);
|
||||
|
||||
/// Interface for subclasses to handle when all handles are closed. Subclasses
|
||||
/// should either call the base version, or assert j6_signal_no_handles.
|
||||
virtual void on_no_handles();
|
||||
void notify_signal_observers();
|
||||
|
||||
j6_koid_t m_koid;
|
||||
j6_signal_t m_signals;
|
||||
uint16_t m_handle_count;
|
||||
|
||||
struct observer_registration
|
||||
{
|
||||
observer_registration(observer* o = nullptr, j6_signal_t s = 0) :
|
||||
object(o), signals(s) {}
|
||||
|
||||
observer *object;
|
||||
j6_signal_t signals;
|
||||
};
|
||||
kutil::vector<observer_registration> m_observers;
|
||||
protected:
|
||||
kutil::vector<thread*> m_blocked_threads;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user