Changeset 878:901526bc034c in freeDiameter
- Timestamp:
- Nov 4, 2012, 1:18:48 AM (11 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
include/freeDiameter/freeDiameter-host.h.in
r849 r878 44 44 #cmakedefine HAVE_CLOCK_GETTIME 45 45 #cmakedefine HAVE_STRNDUP 46 #cmakedefine HAVE_PTHREAD_BAR 46 47 47 48 #cmakedefine HOST_BIG_ENDIAN @HOST_BIG_ENDIAN@ -
tests/CMakeLists.txt
r853 r878 22 22 testsctp 23 23 testostr 24 testfifo 24 25 testpeers 25 26 testdict … … 30 31 testloadext 31 32 ) 32 33 IF(HAVE_PTHREAD_BAR)34 SET(TEST_LIST35 ${TEST_LIST}36 testfifo37 )38 ENDIF(HAVE_PTHREAD_BAR)39 40 33 41 34 ############################# -
tests/testfifo.c
r768 r878 38 38 #include <limits.h> 39 39 40 /* Wrapper for pthread_barrier stuff on Mac OS X */ 41 #ifndef HAVE_PTHREAD_BAR 42 43 #define PTHREAD_BARRIER_SERIAL_THREAD 1 44 typedef struct { 45 int count; 46 int entered; 47 int serial; 48 pthread_mutex_t mutex; 49 pthread_cond_t cond; 50 } pthread_barrier_t; 51 52 int pthread_barrier_init(pthread_barrier_t * barrier, int * barrier_attr, int count) 53 { 54 memset(barrier, 0, sizeof(pthread_barrier_t)); 55 barrier->count = count; 56 pthread_mutex_init(&barrier->mutex, NULL); 57 pthread_cond_init(&barrier->cond, NULL); 58 return 0; 59 } 60 61 int pthread_barrier_destroy(pthread_barrier_t * barrier) 62 { 63 pthread_mutex_destroy(&barrier->mutex); 64 pthread_cond_destroy(&barrier->cond); 65 return 0; 66 } 67 68 int pthread_barrier_wait(pthread_barrier_t * barrier) 69 { 70 int ret = 0; 71 int serial; 72 pthread_mutex_lock(&barrier->mutex); 73 serial = barrier->serial; 74 75 /* first thread gets the special value */ 76 if (barrier->entered++ == 0) 77 ret = PTHREAD_BARRIER_SERIAL_THREAD; 78 79 /* Count was achieved? */ 80 if (barrier->entered == barrier->count) { 81 /* Ok, increase serial, reset number of threads, and signal everyone */ 82 barrier->entered = 0; 83 barrier->serial++; 84 pthread_cond_broadcast(&barrier->cond); 85 } else { 86 do { 87 pthread_cond_wait(&barrier->cond, &barrier->mutex); 88 } while (barrier->serial == serial); 89 /* this protects against spurious wakes */ 90 } 91 pthread_mutex_unlock(&barrier->mutex); 92 return 0; 93 } 94 95 #endif /* HAVE_PTHREAD_BAR */ 96 40 97 /* Structure for testing threshold function */ 41 98 static struct thrh_test {
Note: See TracChangeset
for help on using the changeset viewer.