summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDarkvater <darkvater@openttd.org>2007-02-01 13:01:05 +0000
committerDarkvater <darkvater@openttd.org>2007-02-01 13:01:05 +0000
commit50909e272b3b41e3c174591c279e6a0f1937766d (patch)
tree17fe58a445461b71cc419e56ead040ca0e5b526c /src
parent3c2cb4871ebef41362b401ddd300445fdb11e8be (diff)
downloadopenttd-50909e272b3b41e3c174591c279e6a0f1937766d.tar.xz
(svn r8508) -Codechange (r5762): [win32] Use an atomic operation to query and set the value of _global_dir_is_in_use for opendir etc to guarantee concurrency.
Diffstat (limited to 'src')
-rw-r--r--src/win32.cpp9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/win32.cpp b/src/win32.cpp
index da129e0d9..a79fda13a 100644
--- a/src/win32.cpp
+++ b/src/win32.cpp
@@ -625,20 +625,19 @@ static void Win32InitializeExceptions(void)
/* suballocator - satisfies most requests with a reusable static instance.
* this avoids hundreds of alloc/free which would fragment the heap.
- * To guarantee reentrancy, we fall back to malloc if the instance is
+ * To guarantee concurrency, we fall back to malloc if the instance is
* already in use (it's important to avoid suprises since this is such a
* low-level routine). */
static DIR _global_dir;
-static bool _global_dir_is_in_use = false;
+static LONG _global_dir_is_in_use = false;
static inline DIR *dir_calloc(void)
{
DIR *d;
- if (_global_dir_is_in_use) {
+ if (InterlockedExchange(&_global_dir_is_in_use, true) == (LONG)true) {
d = CallocT<DIR>(1);
} else {
- _global_dir_is_in_use = true;
d = &_global_dir;
memset(d, 0, sizeof(*d));
}
@@ -648,7 +647,7 @@ static inline DIR *dir_calloc(void)
static inline void dir_free(DIR *d)
{
if (d == &_global_dir) {
- _global_dir_is_in_use = false;
+ _global_dir_is_in_use = (LONG)false;
} else {
free(d);
}