1
0
mirror of https://gitlab.xiph.org/xiph/icecast-common.git synced 2024-11-03 04:17:20 -05:00

Fix: Corrected implementation of thread_cond_timedwait()

This commit is contained in:
Philipp Schafft 2024-02-09 10:08:53 +00:00
parent 85d54c53de
commit 07df2860f8
2 changed files with 15 additions and 4 deletions

View File

@ -513,7 +513,11 @@ void thread_mutex_unlock_c(mutex_t *mutex, int line, char *file)
void thread_cond_create_c(cond_t *cond, int line, char *file)
{
pthread_cond_init(&cond->sys_cond, NULL);
pthread_condattr_t attr;
pthread_condattr_init(&attr);
pthread_condattr_setclock(&attr, CLOCK_MONOTONIC);
pthread_cond_init(&cond->sys_cond, &attr);
pthread_condattr_destroy(&attr);
pthread_mutex_init(&cond->cond_mutex, NULL);
}
@ -537,8 +541,15 @@ void thread_cond_timedwait_c(cond_t *cond, int millis, int line, char *file)
{
struct timespec time;
time.tv_sec = millis/1000;
time.tv_nsec = (millis - time.tv_sec*1000)*1000000;
clock_gettime(CLOCK_MONOTONIC, &time);
time.tv_nsec += millis*1000000;
if (time.tv_nsec >= 1000000000) {
unsigned long int extra = time.tv_nsec / 1000000000;
time.tv_nsec -= extra * 1000000000;
time.tv_sec += extra;
}
pthread_mutex_lock(&cond->cond_mutex);
pthread_cond_timedwait(&cond->sys_cond, &cond->cond_mutex, &time);

View File

@ -120,7 +120,7 @@ typedef mutex_t spin_t;
#define thread_cond_signal(x) thread_cond_signal_c(x,__LINE__,__FILE__)
#define thread_cond_broadcast(x) thread_cond_broadcast_c(x,__LINE__,__FILE__)
#define thread_cond_wait(x) thread_cond_wait_c(x,__LINE__,__FILE__)
#define thread_cond_timedwait(x,t) thread_cond_wait_c(x,t,__LINE__,__FILE__)
#define thread_cond_timedwait(x,t) thread_cond_timedwait_c(x,t,__LINE__,__FILE__)
#define thread_rwlock_create(x) thread_rwlock_create_c(x,__LINE__,__FILE__)
#define thread_rwlock_rlock(x) thread_rwlock_rlock_c(x,__LINE__,__FILE__)
#define thread_rwlock_wlock(x) thread_rwlock_wlock_c(x,__LINE__,__FILE__)