83 panic(
NULL,
"Wait queue with pending threads freed");
172 const uint64_t threadsPerBatch = 64;
179 uint64_t toUnblock = amount < threadsPerBatch ? amount : threadsPerBatch;
188 if (collected == toUnblock)
212 for (
uint64_t i = 0; i < collected; i++)
224 return amountUnblocked;
229 if (waitQueues ==
NULL || amount == 0)
240 for (
uint64_t i = 0; i < amount; i++)
245 for (
uint64_t i = 0; i < amount; i++)
260 for (
uint64_t j = 0; j < amount; j++)
281 for (
uint64_t i = 0; i < amount; i++)
291 panic(
NULL,
"Thread in invalid state in wait_block_setup() state=%d", expected);
340 panic(
NULL,
"Invalid thread state %d in wait_block_commit()", state);
#define assert(expression)
static cpu_t * smp_self_unsafe(void)
Returns a pointer to the cpu_t structure of the current CPU.
static cpu_t * smp_self(void)
Returns a pointer to the cpu_t structure of the current CPU.
static void smp_put(void)
Re-enables interrupts after a call to smp_self().
NORETURN void panic(const interrupt_frame_t *frame, const char *format,...)
Panic the kernel, printing a message and halting.
bool thread_is_note_pending(thread_t *thread)
Check if a thread has a note pending.
thread_state_t
Thread state enum.
@ THREAD_UNBLOCKING
Has started unblocking, used to prevent the same thread being unblocked multiple times.
@ THREAD_PRE_BLOCK
Has started the process of blocking but has not yet been given to a owner cpu.
@ THREAD_BLOCKED
Is blocking and waiting in one or multiple wait queues.
@ THREAD_RUNNING
Is currently running on a cpu.
uint64_t wait_block_commit(void)
Block the currently running thread.
bool wait_block_finalize(interrupt_frame_t *frame, cpu_t *self, thread_t *thread, clock_t uptime)
Finalize blocking of a thread.
uint64_t wait_block_setup(wait_queue_t **waitQueues, uint64_t amount, clock_t timeout)
Setup blocking but dont block yet.
void wait_block_cancel(void)
Cancel blocking.
uint64_t wait_unblock(wait_queue_t *waitQueue, uint64_t amount, errno_t err)
Unblock threads waiting on a wait queue.
void wait_queue_init(wait_queue_t *waitQueue)
Initialize wait queue.
void wait_cpu_ctx_init(wait_cpu_ctx_t *wait, cpu_t *self)
Initialize per-CPU wait context.
void wait_thread_ctx_init(wait_thread_ctx_t *wait)
Initialize per-thread wait context.
void wait_queue_deinit(wait_queue_t *waitQueue)
Deinitialize wait queue.
void wait_unblock_thread(thread_t *thread, errno_t err)
Unblock a specific thread.
void sched_push(thread_t *thread, cpu_t *target)
Pushes a thread onto a scheduling queue.
static void lock_init(lock_t *lock)
Initializes a lock.
#define LOCK_SCOPE(lock)
Acquires a lock for the reminder of the current scope.
static void lock_release(lock_t *lock)
Releases a lock.
static void lock_acquire(lock_t *lock)
Acquires a lock, blocking until it is available.
void timer_notify_self(void)
Trigger timer interrupt on self.
void timer_one_shot(cpu_t *self, clock_t uptime, clock_t timeout)
Schedule a one-shot timer interrupt.
void timer_subscribe(timer_ctx_t *ctx, timer_callback_t callback)
Subscribe to timer interrupts.
clock_t timer_uptime(void)
Time since boot.
#define EINVAL
Invalid argument.
#define EINTR
Interrupted system call.
#define ETIMEDOUT
Connection timed out.
#define errno
Error number variable.
#define LIST_FOR_EACH(elem, list, member)
Iterates over a list.
static list_entry_t * list_first(list_t *list)
Gets the first entry in the list without removing it.
static list_entry_t * list_last(list_t *list)
Gets the last entry in the list without removing it.
static void list_prepend(list_t *list, list_entry_t *head, list_entry_t *entry)
Prepends an entry to the list.
#define LIST_FOR_EACH_SAFE(elem, temp, list, member)
Safely iterates over a list, allowing for element removal during iteration.
static void list_remove(list_t *list, list_entry_t *entry)
Removes a list entry from its current list.
static void list_push(list_t *list, list_entry_t *entry)
Pushes an entry to the end of the list.
static bool list_is_empty(list_t *list)
Checks if a list is empty.
static void list_entry_init(list_entry_t *entry)
Initializes a list entry.
static void list_init(list_t *list)
Initializes a list.
static list_entry_t * list_pop(list_t *list)
Pops the first entry from the list.
clock_t uptime(void)
System call for retreving the time since boot.
#define NULL
Pointer error value.
#define ERR
Integer error value.
#define CONTAINER_OF(ptr, type, member)
Container of macro.
#define CONTAINER_OF_SAFE(ptr, type, member)
Safe container of macro.
__UINT64_TYPE__ clock_t
A nanosecond time.
#define RFLAGS_INTERRUPT_ENABLE
static uint64_t rflags_read()
#define atomic_store(object, desired)
#define atomic_compare_exchange_strong(object, expected, desired)
#define atomic_exchange(object, desired)
#define atomic_load(object)
_PUBLIC void * malloc(size_t size)
_PUBLIC void free(void *ptr)
thread_t * runThread
The currently running thread.
Thread of execution structure.
list_entry_t entry
The entry for the scheduler and wait system.
list_t blockedThreads
List of blocked threads, sorted by deadline.
cpu_t * cpu
The CPU this context belongs to.
wait_queue_t * waitQueue
The wait queue the thread is waiting on.
thread_t * thread
The thread that is waiting.
list_entry_t queueEntry
Used in wait_queue_t->entries.
list_entry_t threadEntry
Used in wait_thread_ctx_t->entries.
list_t entries
List of wait entries for threads waiting on this queue.
wait_cpu_ctx_t * cpu
The wait cpu context of the cpu the thread is blocked on.
clock_t deadline
Deadline for timeout, CLOCKS_NEVER for no timeout.
errno_t err
Error number set when unblocking the thread, EOK for no error.
list_t entries
List of wait entries, one for each wait queue the thread is waiting on.
static void wait_timer_handler(interrupt_frame_t *frame, cpu_t *self)
static void wait_remove_wait_entries(thread_t *thread, errno_t err)