Changeset 1290:7945c75972b0 in freeDiameter
- Timestamp:
- Jun 17, 2015, 12:32:07 AM (9 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
extensions/test_app/ta_bench.c
r1206 r1290 37 37 38 38 #include "test_app.h" 39 39 #include <stdio.h> 40 41 #ifndef __APPLE__ /* they deprecated the semaphore there... */ 40 42 #include <semaphore.h> 41 #include <stdio.h> 43 44 #define my_sem_t sem_t 45 #define my_sem_init sem_init 46 #define my_sem_destroy sem_detroy 47 #define my_sem_timedwait sem_timedwait 48 #define my_sem_post sem_post 49 50 #else // on APPLE 51 #include <sched.h> 52 #include <dispatch/dispatch.h> 53 54 #define my_sem_t dispatch_semaphore_t 55 56 static int my_sem_init(my_sem_t * s, int pshared, unsigned int value ) { 57 *s = dispatch_semaphore_create(value); 58 if (*s == NULL) 59 return ENOMEM; 60 return 0; 61 } 62 63 static int my_sem_destroy(my_sem_t *s) { 64 dispatch_release(*s); 65 *s = NULL; 66 return 0; 67 } 68 69 static int my_sem_timedwait(my_sem_t * s, struct timespec *ts) { 70 struct timespec tsn; 71 int64_t nsec; 72 dispatch_time_t when; 73 74 CHECK_SYS( clock_gettime(CLOCK_REALTIME, &tsn) ); 75 76 nsec = (ts->tv_sec * 1000000000) + ts->tv_nsec 77 - (tsn.tv_sec * 1000000000) - tsn.tv_nsec; 78 79 when = dispatch_time ( DISPATCH_TIME_NOW, nsec ); 80 81 return dispatch_semaphore_wait ( *s, when ) ? ETIMEDOUT : 0; 82 } 83 84 static int my_sem_post(my_sem_t *s) { 85 dispatch_semaphore_signal(*s); 86 return 0; 87 } 88 89 #endif // APPLE 90 91 42 92 43 93 struct ta_mess_info { … … 46 96 }; 47 97 48 static sem_t ta_sem; /* To handle the concurrency */98 static my_sem_t ta_sem; /* To handle the concurrency */ 49 99 50 100 /* Cb called when an answer is received */ … … 110 160 111 161 /* Post the semaphore */ 112 CHECK_SYS_DO( sem_post(&ta_sem), );162 CHECK_SYS_DO( my_sem_post(&ta_sem), ); 113 163 114 164 return; … … 214 264 do { 215 265 /* Do not create more that NB_CONCURRENT_MESSAGES in paralel */ 216 int ret = sem_timedwait(&ta_sem, &end_time);266 int ret = my_sem_timedwait(&ta_sem, &end_time); 217 267 if (ret == -1) { 218 268 ret = errno; … … 270 320 int ta_bench_init(void) 271 321 { 272 CHECK_SYS( sem_init( &ta_sem, 0, ta_conf->bench_concur) );322 CHECK_SYS( my_sem_init( &ta_sem, 0, ta_conf->bench_concur) ); 273 323 274 324 CHECK_FCT( fd_event_trig_regcb(ta_conf->signal, "test_app.bench", ta_bench_start ) ); … … 281 331 // CHECK_FCT_DO( fd_sig_unregister(ta_conf->signal), /* continue */ ); 282 332 283 CHECK_SYS_DO( sem_destroy(&ta_sem), );333 CHECK_SYS_DO( my_sem_destroy(&ta_sem), ); 284 334 285 335 return;
Note: See TracChangeset
for help on using the changeset viewer.