Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


(no commit message)
[palacios.git] / palacios / include / geekos / synch.h
1 /*
2  * Synchronization primitives
3  * Copyright (c) 2001, David H. Hovemeyer <daveho@cs.umd.edu>
4  * $Revision: 1.1.1.1 $
5  * 
6  * This is free software.  You are permitted to use,
7  * redistribute, and modify it as specified in the file "COPYING".
8  */
9
10 #ifndef GEEKOS_SYNCH_H
11 #define GEEKOS_SYNCH_H
12
13 #include <geekos/kthread.h>
14
15 /*
16  * mutex states
17  */
18 enum { MUTEX_UNLOCKED, MUTEX_LOCKED };
19
20 struct Mutex {
21     int state;
22     struct Kernel_Thread* owner;
23     struct Thread_Queue waitQueue;
24 };
25
26 #define MUTEX_INITIALIZER { MUTEX_UNLOCKED, 0, THREAD_QUEUE_INITIALIZER }
27
28 struct Condition {
29     struct Thread_Queue waitQueue;
30 };
31
32 void Mutex_Init(struct Mutex* mutex);
33 void Mutex_Lock(struct Mutex* mutex);
34 void Mutex_Unlock(struct Mutex* mutex);
35
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);
40
41 #define IS_HELD(mutex) \
42     ((mutex)->state == MUTEX_LOCKED && (mutex)->owner == g_currentThread)
43
44 #endif  /* GEEKOS_SYNCH_H */