Compare commits

...

2 Commits

Author SHA1 Message Date
Tristan B. Velloza Kildaire bca816d026 Event
- Use scope guards in `notifyAll()`
2023-06-29 16:10:05 +02:00
Tristan B. Velloza Kildaire f99239471e Event
- Use scope guards in `notify(Thread)`
2023-06-29 16:09:04 +02:00
1 changed files with 17 additions and 12 deletions

View File

@ -394,15 +394,22 @@ public class Event
* thread = the Thread to wake up
* Throws:
* `FatalException` if the underlying
* mechanism failed to notify
* mechanism failed to notify or the
* `Thread` you are trying to wakeup doesn't
* yet have a pipe-pair created for itself
*/
public final void notify(Thread thread)
{
// TODO: Throw error if the thread is not found
/* Lock the pipe-pairs */
pipesLock.lock();
/* On successful exit or exception throw */
scope(exit)
{
/* Unlock the pipe-pairs */
pipesLock.unlock();
}
/* If the thread provided is wait()-ing on this event */
if(thread in pipes)
{
@ -422,15 +429,9 @@ public class Event
// TODO: Make this error configurable, maybe a non-fail mode should ne implementwd
if(!nonFail)
{
/* Unlock the pipe-pairs */
pipesLock.unlock();
throw new FatalException(this, FatalError.NOTIFY_FAILURE, "Provided thread has yet to call wait() atleast once");
}
}
/* Unlock the pipe-pairs */
pipesLock.unlock();
}
/**
@ -445,15 +446,19 @@ public class Event
/* Lock the pipe-pairs */
pipesLock.lock();
/* On successful exit or exception throw */
scope(exit)
{
/* Unlock the pipe-pairs */
pipesLock.unlock();
}
/* Loop through each thread */
foreach(Thread curThread; pipes.keys())
{
/* Notify the current thread */
notify(curThread);
}
/* Unlock the pipe-pairs */
pipesLock.unlock();
}
/**