summaryrefslogtreecommitdiff
path: root/src/lib
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
parent80f71e4393e819cdd234fbf1d07e332694bdcd71 (diff)
add eina barrier to efl tree.
SVN revision: 78100
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/eina/Makefile.am3
-rw-r--r--src/lib/eina/eina_config.h.in5
-rw-r--r--src/lib/eina/eina_inline_lock_barrier.x48
-rw-r--r--src/lib/eina/eina_inline_lock_posix.x34
-rw-r--r--src/lib/eina/eina_inline_lock_win32.x2
-rw-r--r--src/lib/eina/eina_inline_lock_wince.x2
-rw-r--r--src/lib/eina/eina_lock.h8
7 files changed, 101 insertions, 1 deletions
diff --git a/src/lib/eina/Makefile.am b/src/lib/eina/Makefile.am
index c3eb252f50..287b29aa8c 100644
--- a/src/lib/eina/Makefile.am
+++ b/src/lib/eina/Makefile.am
@@ -81,7 +81,8 @@ eina_refcount.h \
81eina_mmap.h \ 81eina_mmap.h \
82eina_xattr.h \ 82eina_xattr.h \
83eina_value.h \ 83eina_value.h \
84eina_inline_value.x 84eina_inline_value.x \
85eina_inline_lock_barrier.x
85 86
86# Will be back for developper after 1.2. 87# Will be back for developper after 1.2.
87# eina_model.h 88# eina_model.h
diff --git a/src/lib/eina/eina_config.h.in b/src/lib/eina/eina_config.h.in
index 8b3b3567a7..979027062b 100644
--- a/src/lib/eina/eina_config.h.in
+++ b/src/lib/eina/eina_config.h.in
@@ -51,6 +51,11 @@
51#define EINA_HAVE_THREADS 51#define EINA_HAVE_THREADS
52#endif 52#endif
53 53
54#ifdef EINA_HAVE_PTHREAD_BARRIER
55# undef EINA_HAVE_PTHREAD_BARRIER
56#endif
57@EINA_CONFIGURE_HAVE_PTHREAD_BARRIER@
58
54#ifdef EINA_HAVE_DEBUG_THREADS 59#ifdef EINA_HAVE_DEBUG_THREADS
55# undef EINA_HAVE_DEBUG_THREADS 60# undef EINA_HAVE_DEBUG_THREADS
56#endif 61#endif
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}
diff --git a/src/lib/eina/eina_inline_lock_posix.x b/src/lib/eina/eina_inline_lock_posix.x
index 86cf1f7a7e..88c4b61c11 100644
--- a/src/lib/eina/eina_inline_lock_posix.x
+++ b/src/lib/eina/eina_inline_lock_posix.x
@@ -544,4 +544,38 @@ eina_semaphore_release(Eina_Semaphore *sem, int count_release EINA_UNUSED)
544 return (sem_post(sem) == 0) ? EINA_TRUE : EINA_FALSE; 544 return (sem_post(sem) == 0) ? EINA_TRUE : EINA_FALSE;
545} 545}
546 546
547#ifdef EINA_HAVE_PTHREAD_BARRIER
548typedef struct _Eina_Barrier Eina_Barrier;
549
550struct _Eina_Barrier
551{
552 pthread_barrier_t barrier;
553};
554
555static inline Eina_Bool
556eina_barrier_new(Eina_Barrier *barrier, int needed)
557{
558 if (!pthread_barrier_init(&(barrier->barrier), NULL, needed))
559 return EINA_TRUE;
560 return EINA_FALSE;
561}
562
563static inline void
564eina_barrier_free(Eina_Barrier *barrier)
565{
566 pthread_barrier_destroy(&(barrier->barrier));
567}
568
569static inline Eina_Bool
570eina_barrier_wait(Eina_Barrier *barrier)
571{
572 pthread_barrier_wait(&(barrier->barrier));
573 return EINA_TRUE;
574}
575
576#else
577#include "eina_inline_lock_barrier.x"
578#endif
579
580
547#endif 581#endif
diff --git a/src/lib/eina/eina_inline_lock_win32.x b/src/lib/eina/eina_inline_lock_win32.x
index 856f97265e..383a543f98 100644
--- a/src/lib/eina/eina_inline_lock_win32.x
+++ b/src/lib/eina/eina_inline_lock_win32.x
@@ -551,4 +551,6 @@ eina_semaphore_release(Eina_Semaphore *sem, int count_release)
551 return ReleaseSemaphore(*sem, count_release, NULL) ? EINA_TRUE : EINA_FALSE; 551 return ReleaseSemaphore(*sem, count_release, NULL) ? EINA_TRUE : EINA_FALSE;
552} 552}
553 553
554#include "eina_inline_lock_barrier.x"
555
554#endif 556#endif
diff --git a/src/lib/eina/eina_inline_lock_wince.x b/src/lib/eina/eina_inline_lock_wince.x
index 38d7e08910..787795977f 100644
--- a/src/lib/eina/eina_inline_lock_wince.x
+++ b/src/lib/eina/eina_inline_lock_wince.x
@@ -204,4 +204,6 @@ eina_semaphore_release(Eina_Semaphore *sem EINA_UNUSED,
204 return EINA_FALSE; 204 return EINA_FALSE;
205} 205}
206 206
207#include "eina_inline_lock_barrier.x"
208
207#endif 209#endif
diff --git a/src/lib/eina/eina_lock.h b/src/lib/eina/eina_lock.h
index 5260ed9c4b..ceb19d7b71 100644
--- a/src/lib/eina/eina_lock.h
+++ b/src/lib/eina/eina_lock.h
@@ -106,6 +106,14 @@ static inline Eina_Bool eina_semaphore_lock(Eina_Semaphore *sem);
106/** @relates static Eina_Bool eina_semaphore_release(sem_t *sem, int count_release) */ 106/** @relates static Eina_Bool eina_semaphore_release(sem_t *sem, int count_release) */
107static inline Eina_Bool eina_semaphore_release(Eina_Semaphore *sem, int count_release); 107static inline Eina_Bool eina_semaphore_release(Eina_Semaphore *sem, int count_release);
108 108
109/** @relates static Eina_Bool eina_barrier_new(Eina_Barrier *barrier, int needed) @since 1.8 */
110static inline Eina_Bool eina_barrier_new(Eina_Barrier *barrier, int needed);
111/** @relates static void eina_barrier_free(Eina_Barrier *barrier); @since 1.8 */
112static inline void eina_barrier_free(Eina_Barrier *barrier);
113/** @relates static Eina_Bool eina_barrier_wait(Eina_Barrier *barrier); @since 1.8 */
114static inline Eina_Bool eina_barrier_wait(Eina_Barrier *barrier);
115
116
109#ifdef EINA_HAVE_DEBUG_THREADS 117#ifdef EINA_HAVE_DEBUG_THREADS
110# define EINA_MAIN_LOOP_CHECK_RETURN_VAL(val) \ 118# define EINA_MAIN_LOOP_CHECK_RETURN_VAL(val) \
111 do { \ 119 do { \