util/u_queue: Replace relative time wait hack with u_cnd_monotonic
Remove the gross hack. The hack was broken too, because it incorrectly added abs_time (a timestamp) to the now (another timestamp). Reviewed-by: Marek Olšák <marek.olsak@amd.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/30491>
This commit is contained in:
committed by
Marge Bot
parent
c40c723336
commit
947a333ec3
+12
-27
@@ -31,6 +31,7 @@
|
||||
#include "util/os_time.h"
|
||||
#include "util/u_string.h"
|
||||
#include "util/u_thread.h"
|
||||
#include "util/timespec.h"
|
||||
#include "u_process.h"
|
||||
|
||||
#if defined(__linux__)
|
||||
@@ -160,7 +161,7 @@ util_queue_fence_signal(struct util_queue_fence *fence)
|
||||
{
|
||||
mtx_lock(&fence->mutex);
|
||||
fence->signalled = true;
|
||||
cnd_broadcast(&fence->cond);
|
||||
u_cnd_monotonic_broadcast(&fence->cond);
|
||||
mtx_unlock(&fence->mutex);
|
||||
}
|
||||
|
||||
@@ -169,7 +170,7 @@ _util_queue_fence_wait(struct util_queue_fence *fence)
|
||||
{
|
||||
mtx_lock(&fence->mutex);
|
||||
while (!fence->signalled)
|
||||
cnd_wait(&fence->cond, &fence->mutex);
|
||||
u_cnd_monotonic_wait(&fence->cond, &fence->mutex);
|
||||
mtx_unlock(&fence->mutex);
|
||||
}
|
||||
|
||||
@@ -177,31 +178,15 @@ bool
|
||||
_util_queue_fence_wait_timeout(struct util_queue_fence *fence,
|
||||
int64_t abs_timeout)
|
||||
{
|
||||
/* This terrible hack is made necessary by the fact that we really want an
|
||||
* internal interface consistent with os_time_*, but cnd_timedwait is spec'd
|
||||
* to be relative to the TIME_UTC clock.
|
||||
*/
|
||||
int64_t rel = abs_timeout - os_time_get_nano();
|
||||
struct timespec ts;
|
||||
timespec_from_nsec(&ts, abs_timeout);
|
||||
|
||||
if (rel > 0) {
|
||||
struct timespec ts;
|
||||
|
||||
timespec_get(&ts, TIME_UTC);
|
||||
|
||||
ts.tv_sec += abs_timeout / (1000*1000*1000);
|
||||
ts.tv_nsec += abs_timeout % (1000*1000*1000);
|
||||
if (ts.tv_nsec >= (1000*1000*1000)) {
|
||||
ts.tv_sec++;
|
||||
ts.tv_nsec -= (1000*1000*1000);
|
||||
}
|
||||
|
||||
mtx_lock(&fence->mutex);
|
||||
while (!fence->signalled) {
|
||||
if (cnd_timedwait(&fence->cond, &fence->mutex, &ts) != thrd_success)
|
||||
break;
|
||||
}
|
||||
mtx_unlock(&fence->mutex);
|
||||
mtx_lock(&fence->mutex);
|
||||
while (!fence->signalled) {
|
||||
if (u_cnd_monotonic_timedwait(&fence->cond, &fence->mutex, &ts) != thrd_success)
|
||||
break;
|
||||
}
|
||||
mtx_unlock(&fence->mutex);
|
||||
|
||||
return fence->signalled;
|
||||
}
|
||||
@@ -211,7 +196,7 @@ util_queue_fence_init(struct util_queue_fence *fence)
|
||||
{
|
||||
memset(fence, 0, sizeof(*fence));
|
||||
(void) mtx_init(&fence->mutex, mtx_plain);
|
||||
cnd_init(&fence->cond);
|
||||
u_cnd_monotonic_init(&fence->cond);
|
||||
fence->signalled = true;
|
||||
}
|
||||
|
||||
@@ -232,7 +217,7 @@ util_queue_fence_destroy(struct util_queue_fence *fence)
|
||||
mtx_lock(&fence->mutex);
|
||||
mtx_unlock(&fence->mutex);
|
||||
|
||||
cnd_destroy(&fence->cond);
|
||||
u_cnd_monotonic_destroy(&fence->cond);
|
||||
mtx_destroy(&fence->mutex);
|
||||
}
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user