X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?p=palacios.git;a=blobdiff_plain;f=test%2Fgeekos_test_vm%2Finclude%2Fgeekos%2Fsynch.h;fp=test%2Fgeekos_test_vm%2Finclude%2Fgeekos%2Fsynch.h;h=5cb95ef3fd846061293c67bb44131c50a3af2e0c;hp=0000000000000000000000000000000000000000;hb=a70930549d1b741704dd7af4e6bb0e89f6f8a519;hpb=afb634a80f946634454a5d067a92aa600227bd93 diff --git a/test/geekos_test_vm/include/geekos/synch.h b/test/geekos_test_vm/include/geekos/synch.h new file mode 100644 index 0000000..5cb95ef --- /dev/null +++ b/test/geekos_test_vm/include/geekos/synch.h @@ -0,0 +1,44 @@ +/* + * Synchronization primitives + * Copyright (c) 2001, David H. Hovemeyer + * $Revision: 1.1 $ + * + * This is free software. You are permitted to use, + * redistribute, and modify it as specified in the file "COPYING". + */ + +#ifndef GEEKOS_SYNCH_H +#define GEEKOS_SYNCH_H + +#include + +/* + * mutex states + */ +enum { MUTEX_UNLOCKED, MUTEX_LOCKED }; + +struct Mutex { + int state; + struct Kernel_Thread* owner; + struct Thread_Queue waitQueue; +}; + +#define MUTEX_INITIALIZER { MUTEX_UNLOCKED, 0, THREAD_QUEUE_INITIALIZER } + +struct Condition { + struct Thread_Queue waitQueue; +}; + +void Mutex_Init(struct Mutex* mutex); +void Mutex_Lock(struct Mutex* mutex); +void Mutex_Unlock(struct Mutex* mutex); + +void Cond_Init(struct Condition* cond); +void Cond_Wait(struct Condition* cond, struct Mutex* mutex); +void Cond_Signal(struct Condition* cond); +void Cond_Broadcast(struct Condition* cond); + +#define IS_HELD(mutex) \ + ((mutex)->state == MUTEX_LOCKED && (mutex)->owner == g_currentThread) + +#endif /* GEEKOS_SYNCH_H */