提交 27ad2815 authored 作者: David Yat Sin's avatar David Yat Sin

Fix for pthread_cond_timedwait


git-svn-id: http://svn.openzap.org/svn/openzap/branches/sangoma_boost@934 a93c3328-9c30-0410-af19-c9cd2b2d52af
上级 39974a35
...@@ -1586,7 +1586,7 @@ static zap_status_t zap_sangoma_boost_stop(zap_span_t *span) ...@@ -1586,7 +1586,7 @@ static zap_status_t zap_sangoma_boost_stop(zap_span_t *span)
zap_queue_destroy(&sangoma_boost_data->boost_queue); zap_queue_destroy(&sangoma_boost_data->boost_queue);
return status; return status;
} }
return ZAP_SUCCESS; return status;
} }
static zap_state_map_t boost_state_map = { static zap_state_map_t boost_state_map = {
......
...@@ -39,7 +39,6 @@ struct zap_mutex { ...@@ -39,7 +39,6 @@ struct zap_mutex {
}; };
#else #else
#include <pthread.h> #include <pthread.h>
#define ZAP_THREAD_CALLING_CONVENTION #define ZAP_THREAD_CALLING_CONVENTION
...@@ -273,6 +272,8 @@ failed: ...@@ -273,6 +272,8 @@ failed:
return ZAP_FAIL; return ZAP_FAIL;
} }
#define ONE_BILLION 1000000000
OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms) OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms)
{ {
#ifdef WIN32 #ifdef WIN32
...@@ -298,17 +299,32 @@ OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms) ...@@ -298,17 +299,32 @@ OZ_DECLARE(zap_status_t) zap_condition_wait(zap_condition_t *condition, int ms)
#else #else
int res = 0; int res = 0;
if (ms > 0) { if (ms > 0) {
struct timeval t;
struct timespec waitms; struct timespec waitms;
waitms.tv_sec = time(NULL) + ( ms / 1000 );
waitms.tv_nsec = 1000 * 1000 * ( ms % 1000 ); condition->cnt++;
res = pthread_cond_timedwait(&condition->condition, condition->mutex->mutex, &waitms);
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 { } else {
res = pthread_cond_wait(&condition->condition, condition->mutex->mutex); res = pthread_cond_wait(&condition->condition, &condition->mutex->mutex);
} }
if (res != 0) { if (res != 0) {
if (res == ETIMEDOUT) { if (res == ETIMEDOUT) {
return ZAP_TIMEOUT; return ZAP_TIMEOUT;
} }
zap_log(ZAP_LOG_CRIT,"pthread_cond_timedwait failed (%d)\n", res);
return ZAP_FAIL; return ZAP_FAIL;
} }
return ZAP_SUCCESS; return ZAP_SUCCESS;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论