From 1694634e3c51e4cb75a9e112aa5fc8880f3a7c16 Mon Sep 17 00:00:00 2001 From: "Tristan B. Kildaire" Date: Tue, 20 Oct 2020 10:01:13 +0200 Subject: [PATCH] Added mutex to `getProperties` --- source/dnetd/dconnection.d | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/source/dnetd/dconnection.d b/source/dnetd/dconnection.d index 3d6edfb..12f8de5 100644 --- a/source/dnetd/dconnection.d +++ b/source/dnetd/dconnection.d @@ -948,8 +948,20 @@ public class DConnection : Thread */ public string getProperty(string propertyName) { + /* The fetched property */ + string propertyValue; + + /* Lock the properties store */ + propertiesLock.lock(); + + /* Check for the property's existence */ + propertyValue = properties[propertyName]; + + /* Unlock the properties store */ + propertiesLock.unlock(); + /* TODO: Error handling */ - return properties[propertyName]; + return propertyValue; } /** @@ -957,7 +969,19 @@ public class DConnection : Thread */ public string[] getProperties() { - return properties.keys(); + /* The list of keys */ + string[] propertiesString; + + /* Lock the properties store */ + propertiesLock.lock(); + + /* Check for the property's existence */ + propertiesString = properties.keys(); + + /* Unlock the properties store */ + propertiesLock.unlock(); + + return propertiesString; } /**