Navigation


Changeset 1290:7945c75972b0 in freeDiameter


Ignore:
Timestamp:
Jun 17, 2015, 12:32:07 AM (9 years ago)
Author:
Sebastien Decugis <sdecugis@freediameter.net>
Branch:
default
Phase:
public
Message:

Fix test_app for Mac OS X. Need to retest on other systems.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • extensions/test_app/ta_bench.c

    r1206 r1290  
    3737
    3838#include "test_app.h"
    39 
     39#include <stdio.h>
     40
     41#ifndef __APPLE__ /* they deprecated the semaphore there... */
    4042#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
     56static 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
     63static int my_sem_destroy(my_sem_t *s) {
     64        dispatch_release(*s);
     65        *s = NULL;
     66        return 0;
     67}
     68
     69static 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
     84static int my_sem_post(my_sem_t *s) {
     85        dispatch_semaphore_signal(*s);
     86        return 0;
     87}
     88
     89#endif // APPLE
     90
     91
    4292
    4393struct ta_mess_info {
     
    4696};
    4797
    48 static sem_t ta_sem; /* To handle the concurrency */
     98static my_sem_t ta_sem; /* To handle the concurrency */
    4999
    50100/* Cb called when an answer is received */
     
    110160       
    111161        /* Post the semaphore */
    112         CHECK_SYS_DO( sem_post(&ta_sem), );
     162        CHECK_SYS_DO( my_sem_post(&ta_sem), );
    113163       
    114164        return;
     
    214264        do {
    215265                /* 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);
    217267                if (ret == -1) {
    218268                        ret = errno;
     
    270320int ta_bench_init(void)
    271321{
    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) );
    273323
    274324        CHECK_FCT( fd_event_trig_regcb(ta_conf->signal, "test_app.bench", ta_bench_start ) );
     
    281331        // CHECK_FCT_DO( fd_sig_unregister(ta_conf->signal), /* continue */ );
    282332       
    283         CHECK_SYS_DO( sem_destroy(&ta_sem), );
     333        CHECK_SYS_DO( my_sem_destroy(&ta_sem), );
    284334       
    285335        return;
Note: See TracChangeset for help on using the changeset viewer.