summaryrefslogtreecommitdiffstats
path: root/threads/synch.h
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2012-03-27 11:51:08 +0200
committermanuel <manuel@mausz.at>2012-03-27 11:51:08 +0200
commit4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b (patch)
tree868c52e06f207b5ec8a3cc141f4b8b2bdfcc165c /threads/synch.h
parenteae0bd57f0a26314a94785061888d193d186944a (diff)
downloadprogos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.tar.gz
progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.tar.bz2
progos-4f670845ff9ab6c48bcb5f7bf4d4ef6dc3c3064b.zip
reorganize file structure to match the upstream requirements
Diffstat (limited to 'threads/synch.h')
-rw-r--r--threads/synch.h51
1 files changed, 51 insertions, 0 deletions
diff --git a/threads/synch.h b/threads/synch.h
new file mode 100644
index 0000000..a19e88b
--- /dev/null
+++ b/threads/synch.h
@@ -0,0 +1,51 @@
1#ifndef THREADS_SYNCH_H
2#define THREADS_SYNCH_H
3
4#include <list.h>
5#include <stdbool.h>
6
7/* A counting semaphore. */
8struct semaphore
9 {
10 unsigned value; /* Current value. */
11 struct list waiters; /* List of waiting threads. */
12 };
13
14void sema_init (struct semaphore *, unsigned value);
15void sema_down (struct semaphore *);
16bool sema_try_down (struct semaphore *);
17void sema_up (struct semaphore *);
18void sema_self_test (void);
19
20/* Lock. */
21struct lock
22 {
23 struct thread *holder; /* Thread holding lock (for debugging). */
24 struct semaphore semaphore; /* Binary semaphore controlling access. */
25 };
26
27void lock_init (struct lock *);
28void lock_acquire (struct lock *);
29bool lock_try_acquire (struct lock *);
30void lock_release (struct lock *);
31bool lock_held_by_current_thread (const struct lock *);
32
33/* Condition variable. */
34struct condition
35 {
36 struct list waiters; /* List of waiting threads. */
37 };
38
39void cond_init (struct condition *);
40void cond_wait (struct condition *, struct lock *);
41void cond_signal (struct condition *, struct lock *);
42void cond_broadcast (struct condition *, struct lock *);
43
44/* Optimization barrier.
45
46 The compiler will not reorder operations across an
47 optimization barrier. See "Optimization Barriers" in the
48 reference guide for more information.*/
49#define barrier() asm volatile ("" : : : "memory")
50
51#endif /* threads/synch.h */