Made reservedTags queue thread safe

This commit is contained in:
Tristan B. Kildaire 2020-09-29 08:47:04 +02:00
parent 90835f3c97
commit 02a29b5293
1 changed files with 26 additions and 2 deletions

View File

@ -45,6 +45,11 @@ public final class Manager
*/
private Mutex notificationMutex;
/**
* The reserved tags mutex
*/
private Mutex reservedTagsMutex;
/**
* The remote host
*/
@ -72,6 +77,9 @@ public final class Manager
/* Initialize the `notificationQueue` mutex */
notificationMutex = new Mutex();
/* Initialize the `reservedTags` mutex */
reservedTagsMutex = new Mutex();
/* Start the watcher */
watcher.start();
@ -256,20 +264,36 @@ public final class Manager
public void reserveTag(ulong tag)
{
/* Lock the reservedTags mutex */
reservedTagsMutex.lock();
/* Add the reserved tag */
reservedTags ~= tag;
/* Unlock the reservedTags mutex */
reservedTagsMutex.unlock();
}
public bool isReservedTag(ulong tag)
{
/* Lock the reservedTags mutex */
reservedTagsMutex.lock();
bool found;
foreach(ulong currentTag; reservedTags)
{
if(currentTag == tag)
{
return true;
found = true;
break;
}
}
return false;
/* Unlock the reservedTags mutex */
reservedTagsMutex.unlock();
return found;
}
public void addNotification(NotificationReply notificationReply)