Tenok
A Linux-like Real-Time Operating System for Robotics and Internet of Things
wait.h
Go to the documentation of this file.
1 
4 #ifndef __KERNEL_WAIT_H__
5 #define __KERNEL_WAIT_H__
6 
7 #include <stdbool.h>
8 
9 #include <common/list.h>
10 #include <kernel/kernel.h>
11 #include <kernel/sched.h>
12 #include <kernel/thread.h>
13 
14 typedef struct list_head wait_queue_head_t;
15 
21 #define DECLARE_WAIT_QUEUE_HEAD(name) LIST_HEAD(name)
22 
28 #define init_waitqueue_head(wq) INIT_LIST_HEAD(wq)
29 
36 #define wait_event(wq_head, condition) \
37  do { \
38  CURRENT_THREAD_INFO(curr_thread); \
39  while (1) { \
40  if (condition) \
41  break; \
42  prepare_to_wait(&wq_head, curr_thread, THREAD_WAIT); \
43  schedule(); \
44  } \
45  } while (0)
46 
55 void prepare_to_wait(struct list_head *wait_list,
56  struct thread_info *thread,
57  int state);
58 
64 void wake_up(struct list_head *wait_list);
65 
71 void wake_up_all(struct list_head *wait_list);
72 
79 void finish_wait(struct thread_info *thread);
80 
81 #endif
Definition: list.h:111
Definition: kernel.h:68
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.
Definition: kernel.c:603
void wake_up_all(struct list_head *wait_list)
Wake up all threads from the wait list.
Definition: kernel.c:653
void finish_wait(struct thread_info *thread)
Move the thread from a wait list into a ready list and set it to be ready.
Definition: kernel.c:615
void wake_up(struct list_head *wait_list)
Wake up the highest priority thread from the wait list.
Definition: kernel.c:627