venus: add vn_gettid helper

Signed-off-by: Yiwei Zhang <zzyiwei@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26179>
This commit is contained in:
Yiwei Zhang
2023-11-11 10:14:57 -08:00
committed by Marge Bot
parent b170c1a391
commit 5b26bebcf4
2 changed files with 13 additions and 3 deletions

View File

@@ -11,7 +11,6 @@
#include "vn_common.h" #include "vn_common.h"
#include <stdarg.h> #include <stdarg.h>
#include <sys/syscall.h>
#include "util/log.h" #include "util/log.h"
#include "util/os_misc.h" #include "util/os_misc.h"
@@ -139,7 +138,7 @@ vn_watchdog_timeout(const struct vn_watchdog *watchdog)
static inline void static inline void
vn_watchdog_release(struct vn_watchdog *watchdog) vn_watchdog_release(struct vn_watchdog *watchdog)
{ {
if (syscall(SYS_gettid) == watchdog->tid) { if (vn_gettid() == watchdog->tid) {
watchdog->tid = 0; watchdog->tid = 0;
mtx_unlock(&watchdog->mutex); mtx_unlock(&watchdog->mutex);
} }
@@ -148,7 +147,7 @@ vn_watchdog_release(struct vn_watchdog *watchdog)
static bool static bool
vn_watchdog_acquire(struct vn_watchdog *watchdog, bool alive) vn_watchdog_acquire(struct vn_watchdog *watchdog, bool alive)
{ {
pid_t tid = syscall(SYS_gettid); pid_t tid = vn_gettid();
if (!watchdog->tid && tid != watchdog->tid && if (!watchdog->tid && tid != watchdog->tid &&
mtx_trylock(&watchdog->mutex) == thrd_success) { mtx_trylock(&watchdog->mutex) == thrd_success) {
/* register as the only waiting thread that monitors the ring. */ /* register as the only waiting thread that monitors the ring. */

View File

@@ -20,6 +20,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/syscall.h>
#include <vulkan/vulkan.h> #include <vulkan/vulkan.h>
#include "c11/threads.h" #include "c11/threads.h"
@@ -458,4 +459,14 @@ vn_object_get_id(const void *obj, VkObjectType type)
} }
} }
static inline pid_t
vn_gettid(void)
{
#ifdef ANDROID
return gettid();
#else
return syscall(SYS_gettid);
#endif
}
#endif /* VN_COMMON_H */ #endif /* VN_COMMON_H */