Don't waste time spinning on a mutex that cannot be unlocked, yield as it may be unlocked by another process, if not then whenever we get back here try again (repeat if same result), else fall through with lock, execute event loop, unlock and yield (as per normal)

This commit is contained in:
Tristan B. Velloza Kildaire 2021-09-07 14:12:31 +02:00
parent 217688767a
commit f5ed565912
1 changed files with 16 additions and 2 deletions

View File

@ -109,8 +109,22 @@ public final class Engine : Thread
{
/* TODO: Implement me */
/* Lock the queue-set */
queueLock.lock();
/**
* TODO: If lock fails, then yield
*/
/**
* Lock the queue-set
*
* Additionally:
* Don't waste time spinning on mutex,
* if it is not lockable then yield
*/
while(!queueLock.tryLock_nothrow())
{
yield();
}
foreach(Queue queue; queues)
{