summaryrefslogtreecommitdiffstats
path: root/src/server/globals.c
diff options
context:
space:
mode:
authorSimon Rettberg2019-07-26 17:22:56 +0200
committerSimon Rettberg2019-07-26 17:22:56 +0200
commitb071050dd6a99c54c5995dc0f5694edd847a2792 (patch)
tree4899a2a88b3005ef69cd0a81fcbe35f7019ddb56 /src/server/globals.c
parent[SERVER] Add pretendClient config option (diff)
downloaddnbd3-b071050dd6a99c54c5995dc0f5694edd847a2792.tar.gz
dnbd3-b071050dd6a99c54c5995dc0f5694edd847a2792.tar.xz
dnbd3-b071050dd6a99c54c5995dc0f5694edd847a2792.zip
[SERVER] Turn all spinlocks into mutexes
Just assume sane platforms offer smart mutexes that have a fast-path with spinlocks internally for locks that have little to no congestion. In all other cases, mutexes should perform better anyways.
Diffstat (limited to 'src/server/globals.c')
-rw-r--r--src/server/globals.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/server/globals.c b/src/server/globals.c
index 010274d..d0de704 100644
--- a/src/server/globals.c
+++ b/src/server/globals.c
@@ -1,5 +1,6 @@
#include "globals.h"
#include "ini.h"
+#include "locks.h"
#include "../shared/log.h"
#include <string.h>
#include <stdlib.h>
@@ -39,7 +40,7 @@ atomic_bool _pretendClient = false;
* ignore certain values which cannot be changed safely at runtime.
*/
static atomic_bool initialLoad = true;
-static pthread_mutex_t loadLock = PTHREAD_MUTEX_INITIALIZER;
+static pthread_mutex_t loadLock;
#define IS_TRUE(value) (atoi(value) != 0 || strcmp(value, "true") == 0 || strcmp(value, "True") == 0 || strcmp(value, "TRUE") == 0)
#define SAVE_TO_VAR_STR(ss, kk) do { if (strcmp(section, #ss) == 0 && strcmp(key, #kk) == 0) { if (_ ## kk != NULL) free(_ ## kk); _ ## kk = strdup(value); } } while (0)
@@ -110,7 +111,10 @@ void globals_loadConfig()
char *name = NULL;
asprintf( &name, "%s/%s", _configDir, CONFIG_FILENAME );
if ( name == NULL ) return;
- if ( pthread_mutex_trylock( &loadLock ) != 0 ) {
+ if ( initialLoad ) {
+ mutex_init( &loadLock );
+ }
+ if ( mutex_trylock( &loadLock ) != 0 ) {
logadd( LOG_INFO, "Ignoring config reload request due to already running reload" );
return;
}
@@ -128,7 +132,7 @@ void globals_loadConfig()
globals_dumpConfig( buffer, sizeof(buffer) );
logadd( LOG_DEBUG1, "Effective configuration:\n%s", buffer );
initialLoad = false;
- pthread_mutex_unlock( &loadLock );
+ mutex_unlock( &loadLock );
}
static void sanitizeFixedConfig()