vulkan: Use timespec_add_nsec in vk_sync_timeline
Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz@gmail.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15651>
This commit is contained in:
parent
0ba22b203d
commit
2f6bca6a74
|
@ -26,6 +26,7 @@
|
||||||
#include <inttypes.h>
|
#include <inttypes.h>
|
||||||
|
|
||||||
#include "util/os_time.h"
|
#include "util/os_time.h"
|
||||||
|
#include "util/timespec.h"
|
||||||
|
|
||||||
#include "vk_alloc.h"
|
#include "vk_alloc.h"
|
||||||
#include "vk_device.h"
|
#include "vk_device.h"
|
||||||
|
@ -420,34 +421,6 @@ vk_sync_timeline_get_value(struct vk_device *device,
|
||||||
return VK_SUCCESS;
|
return VK_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define NSEC_PER_SEC 1000000000ull
|
|
||||||
|
|
||||||
static bool
|
|
||||||
timespec_add_ns_overflow(struct timespec ts, uint64_t ns,
|
|
||||||
struct timespec *ts_out)
|
|
||||||
{
|
|
||||||
STATIC_ASSERT(sizeof(ts.tv_sec) <= sizeof(uint64_t));
|
|
||||||
|
|
||||||
/* We don't know so assume it's signed */
|
|
||||||
const uint64_t max_tv_sec = u_intN_max(sizeof(ts.tv_sec) * 8);
|
|
||||||
|
|
||||||
if (ns / NSEC_PER_SEC > max_tv_sec)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
if (ts.tv_sec > max_tv_sec - ns / NSEC_PER_SEC)
|
|
||||||
return true;
|
|
||||||
|
|
||||||
ts.tv_sec += ns / NSEC_PER_SEC,
|
|
||||||
ts.tv_nsec += ns % NSEC_PER_SEC,
|
|
||||||
|
|
||||||
ts.tv_sec += ts.tv_nsec / NSEC_PER_SEC;
|
|
||||||
ts.tv_nsec = ts.tv_nsec % NSEC_PER_SEC;
|
|
||||||
|
|
||||||
*ts_out = ts;
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
static VkResult
|
static VkResult
|
||||||
vk_sync_timeline_wait_locked(struct vk_device *device,
|
vk_sync_timeline_wait_locked(struct vk_device *device,
|
||||||
struct vk_sync_timeline *timeline,
|
struct vk_sync_timeline *timeline,
|
||||||
|
@ -475,13 +448,14 @@ vk_sync_timeline_wait_locked(struct vk_device *device,
|
||||||
*/
|
*/
|
||||||
uint64_t rel_timeout_ns = abs_timeout_ns - now_ns;
|
uint64_t rel_timeout_ns = abs_timeout_ns - now_ns;
|
||||||
|
|
||||||
struct timespec abstime;
|
struct timespec now_ts, abs_timeout_ts;
|
||||||
timespec_get(&abstime, TIME_UTC);
|
timespec_get(&now_ts, TIME_UTC);
|
||||||
if (timespec_add_ns_overflow(abstime, rel_timeout_ns, &abstime)) {
|
if (timespec_add_nsec(&abs_timeout_ts, &now_ts, rel_timeout_ns)) {
|
||||||
/* Overflowed; may as well be infinite */
|
/* Overflowed; may as well be infinite */
|
||||||
ret = cnd_wait(&timeline->cond, &timeline->mutex);
|
ret = cnd_wait(&timeline->cond, &timeline->mutex);
|
||||||
} else {
|
} else {
|
||||||
ret = cnd_timedwait(&timeline->cond, &timeline->mutex, &abstime);
|
ret = cnd_timedwait(&timeline->cond, &timeline->mutex,
|
||||||
|
&abs_timeout_ts);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (ret == thrd_error)
|
if (ret == thrd_error)
|
||||||
|
|
Loading…
Reference in New Issue