Mesa (main): vulkan: Use timespec_add_nsec in vk_sync_timeline
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Wed Apr 6 01:05:45 UTC 2022
Module: Mesa
Branch: main
Commit: 2f6bca6a74a88706e7077908d8e3c8615422d2d9
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=2f6bca6a74a88706e7077908d8e3c8615422d2d9
Author: Jason Ekstrand <jason.ekstrand at collabora.com>
Date: Tue Mar 29 13:14:27 2022 -0500
vulkan: Use timespec_add_nsec in vk_sync_timeline
Reviewed-By: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/15651>
---
src/vulkan/runtime/vk_sync_timeline.c | 38 ++++++-----------------------------
1 file changed, 6 insertions(+), 32 deletions(-)
diff --git a/src/vulkan/runtime/vk_sync_timeline.c b/src/vulkan/runtime/vk_sync_timeline.c
index 7bb974d752e..d2d712daa84 100644
--- a/src/vulkan/runtime/vk_sync_timeline.c
+++ b/src/vulkan/runtime/vk_sync_timeline.c
@@ -26,6 +26,7 @@
#include <inttypes.h>
#include "util/os_time.h"
+#include "util/timespec.h"
#include "vk_alloc.h"
#include "vk_device.h"
@@ -420,34 +421,6 @@ vk_sync_timeline_get_value(struct vk_device *device,
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
vk_sync_timeline_wait_locked(struct vk_device *device,
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;
- struct timespec abstime;
- timespec_get(&abstime, TIME_UTC);
- if (timespec_add_ns_overflow(abstime, rel_timeout_ns, &abstime)) {
+ struct timespec now_ts, abs_timeout_ts;
+ timespec_get(&now_ts, TIME_UTC);
+ if (timespec_add_nsec(&abs_timeout_ts, &now_ts, rel_timeout_ns)) {
/* Overflowed; may as well be infinite */
ret = cnd_wait(&timeline->cond, &timeline->mutex);
} else {
- ret = cnd_timedwait(&timeline->cond, &timeline->mutex, &abstime);
+ ret = cnd_timedwait(&timeline->cond, &timeline->mutex,
+ &abs_timeout_ts);
}
}
if (ret == thrd_error)
More information about the mesa-commit
mailing list