From 0f9894f79bd5162858830f5c6e665fa7d381def5 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Thu, 8 Jun 2023 12:28:30 -0700 Subject: [PATCH] QSemaphore: emit waking on the same word size as we wait on MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit futexSemaphoreTryAcquire_loop() always waits on 32-bit portions of QSemaphore. The current implementations only look at the pointer address and don't care what size the waiter used. That's not the case for the Darwin/macOS implementation: In xnu/bsd/kern/sys_ulock.c:ulock_wake[1]: if (opcode != ull->ull_opcode) { ret = EDOM; goto out_ull_put; } [1] https://github.com/apple-oss-distributions/xnu/blob/5c2921b07a2480ab43ec66f5b9e41cb872bc554f/bsd/kern/sys_ulock.c#L970-L973 Change-Id: I63b988479db546dabffcfffd1766c5eae61187f0 Reviewed-by: Fabian Kosmale Reviewed-by: MÃ¥rten Nordheim --- src/corelib/thread/qsemaphore.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/corelib/thread/qsemaphore.cpp b/src/corelib/thread/qsemaphore.cpp index 95893d731e5..73e88cf42c8 100644 --- a/src/corelib/thread/qsemaphore.cpp +++ b/src/corelib/thread/qsemaphore.cpp @@ -379,12 +379,9 @@ void QSemaphore::release(int n) // its acquisition anyway, so it has to wait; // 2) it did not see the new counter value, in which case its // futexWait will fail. - if (futexHasWaiterCount) { - futexWakeAll(*futexLow32(&u)); + futexWakeAll(*futexLow32(&u)); + if (futexHasWaiterCount) futexWakeAll(*futexHigh32(&u)); - } else { - futexWakeAll(u); - } } return; }