2 * Synchronization primitives
3 * Copyright (c) 2001, David H. Hovemeyer <daveho@cs.umd.edu>
6 * This is free software. You are permitted to use,
7 * redistribute, and modify it as specified in the file "COPYING".
10 #ifndef GEEKOS_SYNCH_H
11 #define GEEKOS_SYNCH_H
13 #include <geekos/kthread.h>
18 enum { MUTEX_UNLOCKED, MUTEX_LOCKED };
22 struct Kernel_Thread* owner;
23 struct Thread_Queue waitQueue;
26 #define MUTEX_INITIALIZER { MUTEX_UNLOCKED, 0, THREAD_QUEUE_INITIALIZER }
29 struct Thread_Queue waitQueue;
32 void Mutex_Init(struct Mutex* mutex);
33 void Mutex_Lock(struct Mutex* mutex);
34 void Mutex_Unlock(struct Mutex* mutex);
36 void Cond_Init(struct Condition* cond);
37 void Cond_Wait(struct Condition* cond, struct Mutex* mutex);
38 void Cond_Signal(struct Condition* cond);
39 void Cond_Broadcast(struct Condition* cond);
41 #define IS_HELD(mutex) \
42 ((mutex)->state == MUTEX_LOCKED && (mutex)->owner == g_currentThread)
44 #endif /* GEEKOS_SYNCH_H */