]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Fix for pthread_cond_timedwait
authorDavid Yat Sin <dyatsin@sangoma.com>
Wed, 9 Dec 2009 21:45:09 +0000 (21:45 +0000)
committerDavid Yat Sin <dyatsin@sangoma.com>
Wed, 9 Dec 2009 21:45:09 +0000 (21:45 +0000)
git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@934 a93c3328-9c30-0410-af19-c9cd2b2d52af

libs/freetdm/src/ozmod/ozmod_sangoma_boost/ozmod_sangoma_boost.c
libs/freetdm/src/zap_threadmutex.c

index b4af623c0a76af5629d9481d014e0d0f22bbf786..0d2b30f8bcecf321c9357765bb992bca0278c774 100644 (file)
@@ -1586,7 +1586,7 @@ static zap_status_t zap_sangoma_boost_stop(zap_span_t *span)
                zap_queue_destroy(&sangoma_boost_data->boost_queue);
                return status;
        }
-       return ZAP_SUCCESS;
+       return status;
 }
 
 static zap_state_map_t boost_state_map = {
index f5cc4a6117d44754480c76273b7726351b1cbe4f..44591eed84422990c1ceedcdb25db351b8a9b8a2 100644 (file)
@@ -39,7 +39,6 @@ struct zap_mutex {
 };
 
 #else
-
 #include <pthread.h>
 
 #define ZAP_THREAD_CALLING_CONVENTION
@@ -273,6 +272,8 @@ failed:
        return ZAP_FAIL;
 }
 
+#define ONE_BILLION 1000000000
+
 OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms)
 {
 #ifdef WIN32
@@ -298,17 +299,32 @@ OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms)
 #else
        int res = 0;
        if (ms > 0) {
-               struct timespec waitms; 
-               waitms.tv_sec = time(NULL) + ( ms / 1000 );
-               waitms.tv_nsec = 1000 * 1000 * ( ms % 1000 );
-               res = pthread_cond_timedwait(&condition->condition, condition->mutex->mutex, &waitms);
+               struct timeval t;
+               
+               struct timespec waitms;
+
+               condition->cnt++;
+
+               gettimeofday(&t, NULL);
+
+               waitms.tv_sec = t.tv_sec + ( ms / 1000 );
+
+               waitms.tv_nsec = 1000*(t.tv_usec + (1000 * ( ms % 1000 )));
+
+               if (waitms.tv_nsec > ONE_BILLION) {
+                               waitms.tv_sec++;
+                               waitms.tv_nsec-= ONE_BILLION;
+               }
+
+               res = pthread_cond_timedwait(&condition->condition, &condition->mutex->mutex, &waitms);
        } else {
-               res = pthread_cond_wait(&condition->condition, condition->mutex->mutex);
+               res = pthread_cond_wait(&condition->condition, &condition->mutex->mutex);
        }
        if (res != 0) {
                if (res == ETIMEDOUT) {
                        return ZAP_TIMEOUT;
                }
+               zap_log(ZAP_LOG_CRIT,"pthread_cond_timedwait failed (%d)\n", res);
                return ZAP_FAIL;
        }
        return ZAP_SUCCESS;