#pragma once #include "kthread.h" struct wait_queue { struct kthread *thread; struct wait_queue *next; struct wait_queue *prev; }; #define __WAITQUEUE_INITIALIZER(name) \ { \ .thread = NULL, .next = NULL, .prev = NULL \ } #define DECLARE_WAITQUEUE(name) \ struct wait_queue name = __WAITQUEUE_INITIALIZER(name) int wait(struct wait_queue *); int waitTimeout(struct wait_queue *wq, unsigned long msec); int wake_up(struct wait_queue *); #define wait_event(wq, condition) \ do { \ if (condition) \ break; \ wait(wq); \ } while (1) struct semaphore { int count; struct wait_queue *wait; }; struct mutex { struct kthread *owner; struct wait_queue *wait; };