summaryrefslogtreecommitdiff
path: root/src/lib/eina/eina_inline_lock_barrier.x
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2012-10-17 03:55:35 +0000
committerCarsten Haitzler <raster@rasterman.com>2012-10-17 03:55:35 +0000
commit42a59387a67f4c5c9604b2ae36a3cbbf5e02f47f (patch)
tree08a293318a149e105b32ab67dbe9fd3dfe451ea9 /src/lib/eina/eina_inline_lock_barrier.x
parent80f71e4393e819cdd234fbf1d07e332694bdcd71 (diff)
add eina barrier to efl tree.
SVN revision: 78100
Diffstat (limited to 'src/lib/eina/eina_inline_lock_barrier.x')
-rw-r--r--src/lib/eina/eina_inline_lock_barrier.x48
1 files changed, 48 insertions, 0 deletions
diff --git a/src/lib/eina/eina_inline_lock_barrier.x b/src/lib/eina/eina_inline_lock_barrier.x
new file mode 100644
index 0000000000..536e26c6d5
--- /dev/null
+++ b/src/lib/eina/eina_inline_lock_barrier.x
@@ -0,0 +1,48 @@
1typedef struct _Eina_Barrier Eina_Barrier;
2
3struct _Eina_Barrier
4{
5 int needed, called;
6 Eina_Lock lock, cond_lock;
7 Eina_Condition cond;
8};
9
10static inline Eina_Bool
11eina_barrier_new(Eina_Barrier *barrier, int needed)
12{
13 barrier->needed = needed;
14 barrier->called = 0;
15 if (!eina_lock_new(&(barrier->lock)))
16 return EINA_FALSE;
17 if (!eina_lock_new(&(barrier->cond_lock)))
18 return EINA_FALSE;
19 if (!eina_condition_new(&(barrier->cond), &(barrier->cond_lock)))
20 return EINA_FALSE;
21 return EINA_TRUE;
22}
23
24static inline void
25eina_barrier_free(Eina_Barrier *barrier)
26{
27 eina_condition_free(&(barrier->cond));
28 eina_lock_free(&(barrier->cond_lock));
29 eina_lock_free(&(barrier->lock));
30 barrier->needed = 0;
31 barrier->called = 0;
32}
33
34static inline Eina_Bool
35eina_barrier_wait(Eina_Barrier *barrier)
36{
37 eina_lock_take(&(barrier->lock));
38 barrier->called++;
39 if (barrier->called == barrier->needed)
40 {
41 barrier->called = 0;
42 eina_condition_broadcast(&(barrier->cond));
43 }
44 else
45 eina_condition_wait(&(barrier->cond));
46 eina_lock_release(&(barrier->lock));
47 return EINA_TRUE;
48}