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);
35 void Mutex_Destroy(struct Mutex *mutex);
37 void Cond_Init(struct Condition* cond);
38 void Cond_Wait(struct Condition* cond, struct Mutex* mutex);
39 int Cond_Wait_Timeout(struct Condition * cond, struct Mutex * mutex, uint_t ms);
40 void Cond_Signal(struct Condition* cond);
41 void Cond_Broadcast(struct Condition* cond);
42 void Cond_Destroy(struct Condition *cond);
44 #define IS_HELD(mutex) \
45 ((mutex)->state == MUTEX_LOCKED && (mutex)->owner == g_currentThread)
47 #endif /* GEEKOS_SYNCH_H */