My Kernel v0.1.0

Waiting queue. More...

Collaboration diagram for Waitqueue:

Data Structures

struct  waitqueue
 Waiting Queue. More...
 

Macros

#define __WAITQUEUE_INIT(_queue)
 Default init value.
 
#define __INIT_WAITQUEUE(_queue)   _queue = __WAITQUEUE_INIT(_queue)
 Initialize a waitqueue.
 
#define DECLARE_WAITQUEUE(_queue)   struct waitqueue INIT_WAITQUEUE(_queue)
 Declare and initialize a waitqueue.
 
#define waitqueue_enqueue(waitqueue, thread)
 Mark a thread as waiting for the event to finish.
 

Functions

bool waitqueue_is_empty (struct waitqueue *)
 Check whether anyone is waiting for this event to finish.
 
void waitqueue_enqueue_locked (struct waitqueue *, struct thread *)
 Mark a thread as waiting for the event to finish. More...
 
const struct threadwaitqueue_peek (struct waitqueue *)
 
struct threadwaitqueue_dequeue (struct waitqueue *)
 Wakeup the first thread inside the queue. More...
 
size_t waitqueue_dequeue_all (struct waitqueue *)
 Wakeup all the threads inside the queue. More...
 

Detailed Description

A waitqueue is used to list threads that are waiting for a ressource before being rescheduled.

Some examples are:

All accesses to a waitqueue are placed behind a lock to make this API thread safe.

Usage

A waitqueue is used exactly as you would a regular queue. The only difference is that when a thread is queued it is automatically marked as waiting, and resumes running once dequeued.

Function Documentation

◆ waitqueue_dequeue()

struct thread * waitqueue_dequeue ( struct waitqueue queue)
Returns
The thread that was waken up

◆ waitqueue_dequeue_all()

size_t waitqueue_dequeue_all ( struct waitqueue queue)
Returns
The number of threads that were waken up

◆ waitqueue_enqueue_locked()

void waitqueue_enqueue_locked ( struct waitqueue queue,
struct thread thread 
)

This function is equivalent to waitqueue_enqueue. It should be called when holding the queue's lock.

NOTE: This function releases the lock held by the caller

◆ waitqueue_peek()

const struct thread * waitqueue_peek ( struct waitqueue queue)
Returns
The first thread inside the waitqueue