Use the new B_ABSOLUTE_REAL_TIME_TIMEOUT. Fixes pthread_cond_timedwait()

and pthread_mutex_timedlock() which were waiting system time relative
although their timeout parameter is Epoch relative.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25435 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2008-05-10 21:44:03 +00:00
parent 4d3680aaef
commit a636a33926
3 changed files with 7 additions and 6 deletions
+2 -4
View File
@@ -15,7 +15,6 @@
#include <fs/KPath.h> #include <fs/KPath.h>
#include <kernel.h> #include <kernel.h>
#include <lock.h> #include <lock.h>
#include <real_time_clock.h>
#include <syscall_restart.h> #include <syscall_restart.h>
#include <team.h> #include <team.h>
#include <thread.h> #include <thread.h>
@@ -740,9 +739,8 @@ struct realtime_sem_context {
} else if (timeout == B_INFINITE_TIMEOUT) { } else if (timeout == B_INFINITE_TIMEOUT) {
error = acquire_sem_etc(id, 1, B_CAN_INTERRUPT, 0); error = acquire_sem_etc(id, 1, B_CAN_INTERRUPT, 0);
} else { } else {
error = acquire_sem_etc(id, 1, B_CAN_INTERRUPT | B_ABSOLUTE_TIMEOUT, error = acquire_sem_etc(id, 1,
timeout - rtc_boot_time()); B_CAN_INTERRUPT | B_ABSOLUTE_REAL_TIME_TIMEOUT, timeout);
// The given absolute timeout is relative to the Epoch.
} }
return error == B_BAD_SEM_ID ? B_BAD_VALUE : error; return error == B_BAD_SEM_ID ? B_BAD_VALUE : error;
@@ -108,7 +108,8 @@ cond_wait(pthread_cond *cond, pthread_mutex_t *_mutex, bigtime_t timeout)
do { do {
status = acquire_sem_etc(cond->sem, 1, status = acquire_sem_etc(cond->sem, 1,
timeout == B_INFINITE_TIMEOUT ? 0 : B_ABSOLUTE_TIMEOUT, timeout); timeout == B_INFINITE_TIMEOUT ? 0 : B_ABSOLUTE_REAL_TIME_TIMEOUT,
timeout);
} while (status == B_OK && atomic_get(&cond->event_counter) == event); } while (status == B_OK && atomic_get(&cond->event_counter) == event);
pthread_mutex_lock(_mutex); pthread_mutex_lock(_mutex);
@@ -147,7 +147,9 @@ mutex_lock(pthread_mutex *mutex, bigtime_t timeout)
if (!mutex->attr.process_shared || atomic_add(&mutex->count, 1) > 0) { if (!mutex->attr.process_shared || atomic_add(&mutex->count, 1) > 0) {
// this mutex is already locked by someone else, so we need // this mutex is already locked by someone else, so we need
// to wait // to wait
status = acquire_sem_etc(mutex->sem, 1, timeout == B_INFINITE_TIMEOUT ? 0 : B_ABSOLUTE_TIMEOUT, timeout); status = acquire_sem_etc(mutex->sem, 1,
timeout == B_INFINITE_TIMEOUT ? 0 : B_ABSOLUTE_REAL_TIME_TIMEOUT,
timeout);
} }
if (status == B_OK) { if (status == B_OK) {