mirror of
https://github.com/moonlight-stream/moonlight-common-c.git
synced 2025-08-18 09:25:49 +00:00
Elide the wait if the queue head is already non-null
This commit is contained in:
parent
edf1838708
commit
71c9ff0d91
@ -184,10 +184,15 @@ int LbqWaitForQueueElement(PLINKED_BLOCKING_QUEUE queueHead, void** data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
// We can also avoid a syscall if the head pointer is non-NULL.
|
||||||
|
// It's not safe to dereference the value due to potential memory
|
||||||
|
// ordering hazards, but we can use its presence to elide the wait.
|
||||||
|
if (queueHead->head == NULL) {
|
||||||
err = PltWaitForEvent(&queueHead->containsDataEvent);
|
err = PltWaitForEvent(&queueHead->containsDataEvent);
|
||||||
if (err != PLT_WAIT_SUCCESS) {
|
if (err != PLT_WAIT_SUCCESS) {
|
||||||
return LBQ_INTERRUPTED;
|
return LBQ_INTERRUPTED;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (queueHead->shutdown) {
|
if (queueHead->shutdown) {
|
||||||
return LBQ_INTERRUPTED;
|
return LBQ_INTERRUPTED;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user