From 3ae9e95461ea2e025330df4bda372fac9615b3ca Mon Sep 17 00:00:00 2001 From: Bob Chen Date: Tue, 5 Dec 2023 09:59:44 +0800 Subject: [PATCH] Mute an UBSan check error for SCOPED_LOCK macro (#283) --- thread/thread.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/thread/thread.cpp b/thread/thread.cpp index 1a6d3fe6..bde8ab21 100644 --- a/thread/thread.cpp +++ b/thread/thread.cpp @@ -72,8 +72,6 @@ inline int posix_memalign(void** memptr, size_t alignment, size_t size) { by target vcpu in resume_thread(), when its runq becomes empty; */ -#define SCOPED_MEMBER_LOCK(x) SCOPED_LOCK(&(x)->lock, ((bool)x) * 2) - // Define assembly section header for clang and gcc #if defined(__APPLE__) #define DEF_ASM_FUNC(name) ".text\n" \ @@ -1199,7 +1197,8 @@ R"( __attribute__((always_inline)) inline Switch prepare_usleep(uint64_t useconds, thread_list* waitq, RunQ rq = {}) { - SCOPED_MEMBER_LOCK(waitq); + spinlock* waitq_lock = waitq ? &waitq->lock : nullptr; + SCOPED_LOCK(waitq_lock, ((bool) waitq) * 2); SCOPED_LOCK(rq.current->lock); assert(!AtomicRunQ(rq).single()); auto sw = AtomicRunQ(rq).remove_current(states::SLEEPING);