Tenok
A Linux-like Real-Time Operating System for Robotics and Internet of Things
Macros | Typedefs | Functions
wait.h File Reference
#include <stdbool.h>
#include <common/list.h>
#include <kernel/kernel.h>
#include <kernel/sched.h>
#include <kernel/thread.h>
Include dependency graph for wait.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define DECLARE_WAIT_QUEUE_HEAD(name)   LIST_HEAD(name)
 Declare and initialize a wait queue. More...
 
#define init_waitqueue_head(wq)   INIT_LIST_HEAD(wq)
 Initialize the wait queue. More...
 
#define wait_event(wq_head, condition)
 Wait until the condition became true. More...
 

Typedefs

typedef struct list_head wait_queue_head_t
 

Functions

void prepare_to_wait (struct list_head *wait_list, struct thread_info *thread, int state)
 Suspend current thread and place it into a wait list with a new state. More...
 
void wake_up (struct list_head *wait_list)
 Wake up the highest priority thread from the wait list. More...
 
void wake_up_all (struct list_head *wait_list)
 Wake up all threads from the wait list. More...
 
void finish_wait (struct thread_info *thread)
 Move the thread from a wait list into a ready list and set it to be ready. More...
 

Macro Definition Documentation

◆ DECLARE_WAIT_QUEUE_HEAD

#define DECLARE_WAIT_QUEUE_HEAD (   name)    LIST_HEAD(name)

Declare and initialize a wait queue.

Parameters
nameName of the wait queue variable.
Return values
None

◆ init_waitqueue_head

#define init_waitqueue_head (   wq)    INIT_LIST_HEAD(wq)

Initialize the wait queue.

Parameters
listThe wait queue to initialize.
Return values
None

◆ wait_event

#define wait_event (   wq_head,
  condition 
)
Value:
do { \
CURRENT_THREAD_INFO(curr_thread); \
while (1) { \
if (condition) \
break; \
prepare_to_wait(&wq_head, curr_thread, THREAD_WAIT); \
schedule(); \
} \
} while (0)

Wait until the condition became true.

Parameters
wq_headThe wait queue to sleep.
conditionThe condition to wait until true.
Return values
None

Function Documentation

◆ finish_wait()

void finish_wait ( struct thread_info thread)

Move the thread from a wait list into a ready list and set it to be ready.

Parameters
waitThe pointer that point to the thread to wake up.
Return values
None

◆ prepare_to_wait()

void prepare_to_wait ( struct list_head wait_list,
struct thread_info thread,
int  state 
)

Suspend current thread and place it into a wait list with a new state.

Parameters
wait_listThread waiting list.
threadThe thread to to place in the wait list.
stateThe new state of the thread.
Return values
None

◆ wake_up()

void wake_up ( struct list_head wait_list)

Wake up the highest priority thread from the wait list.

Parameters
wait_listThe wait list that contains suspended threads.
Return values
None

◆ wake_up_all()

void wake_up_all ( struct list_head wait_list)

Wake up all threads from the wait list.

Parameters
wait_listThe wait list that contains suspended threads.
Return values
None