MentOS  0.8.0
The Mentoring Operating System
wait.h
Go to the documentation of this file.
1 
6 #pragma once
7 
8 #include "sys/list_head.h"
9 #include "klib/spinlock.h"
10 
12 #define WNOHANG 0x00000001
15 #define WUNTRACED 0x00000002
18 #define WIFSIGNALED(status) (!WIFSTOPPED(status) && !WIFEXITED(status))
22 #define WIFSTOPPED(status) (((status)&0xff) == 0x7f)
28 #define WEXITSTATUS(status) (((status)&0xff00) >> 8)
32 #define WTERMSIG(status) ((status)&0x7f)
34 #define WIFEXITED(status) (WTERMSIG(status) == 0)
37 #define WSTOPSIG(status) (WEXITSTATUS(status))
38 
39 //==== Task States ============================================================
40 #define TASK_RUNNING 0x00
41 #define TASK_INTERRUPTIBLE (1 << 0)
42 #define TASK_UNINTERRUPTIBLE (1 << 1)
43 #define TASK_STOPPED (1 << 2)
44 #define TASK_TRACED (1 << 3)
45 #define EXIT_ZOMBIE (1 << 4)
46 #define EXIT_DEAD (1 << 5)
47 //==============================================================================
48 
51 
54 #define WQ_FLAG_EXCLUSIVE 0x01
55 //#define WQ_FLAG_WOKEN 0x02
56 //#define WQ_FLAG_BOOKMARK 0x04
57 //#define WQ_FLAG_CUSTOM 0x08
58 //#define WQ_FLAG_DONE 0x10
59 
61 
63 typedef struct wait_queue_head_t {
67  struct list_head task_list;
69 
71 typedef struct wait_queue_entry_t {
73  unsigned int flags;
75  struct task_struct *task;
77  int (*func)(struct wait_queue_entry_t *wait, unsigned mode, int sync);
79  struct list_head task_list;
81 
82 
86 
89 void wait_queue_entry_dealloc(wait_queue_entry_t * wait_queue_entry);
90 
95 
100 
105 
111 int default_wake_function(wait_queue_entry_t *wait, unsigned mode, int sync);
112 
pid_t wait(int *status)
Suspends the execution of the calling thread until ANY child has changed state.
Definition: waitpid.c:35
struct wait_queue_head_t wait_queue_head_t
Head of the waiting queue.
wait_queue_entry_t * sleep_on(wait_queue_head_t *wq)
Sets the state of the current process to TASK_UNINTERRUPTIBLE and inserts it into the specified wait ...
Definition: scheduler.c:241
int default_wake_function(wait_queue_entry_t *wait, unsigned mode, int sync)
The default wake function, a wrapper for try_to_wake_up.
Definition: scheduler.c:235
void add_wait_queue(wait_queue_head_t *head, wait_queue_entry_t *wq)
Adds the element to the waiting queue.
Definition: wait.c:66
wait_queue_entry_t * wait_queue_entry_alloc(void)
Allocates the memory for a wait_queue_entry.
Definition: wait.c:33
struct wait_queue_entry_t wait_queue_entry_t
Entry of the waiting queue.
void init_waitqueue_entry(wait_queue_entry_t *wq, struct task_struct *task)
Initialize the waiting queue entry.
Definition: wait.c:59
void remove_wait_queue(wait_queue_head_t *head, wait_queue_entry_t *wq)
Removes the element from the waiting queue.
Definition: wait.c:74
void wait_queue_entry_dealloc(wait_queue_entry_t *wait_queue_entry)
Frees the memory of a wait_queue_entry.
Definition: wait.c:51
atomic_t spinlock_t
Spinlock structure.
Definition: spinlock.h:16
this is our task object. Every process in the system has this, and it holds a lot of information....
Definition: process.h:82
Entry of the waiting queue.
Definition: wait.h:71
struct task_struct * task
Task associated with the wait queue entry.
Definition: wait.h:75
int(* func)(struct wait_queue_entry_t *wait, unsigned mode, int sync)
Function associated with the wait queue entry.
Definition: wait.h:77
unsigned int flags
Flags of the type WaitQueueFlags.
Definition: wait.h:73
struct list_head task_list
Handler for placing the entry inside a waiting queue double linked-list.
Definition: wait.h:79
Head of the waiting queue.
Definition: wait.h:63
struct list_head task_list
Head of the waiting queue, it contains wait_queue_entry_t elements.
Definition: wait.h:67
spinlock_t lock
Locking element for the waiting queque.
Definition: wait.h:65