switching back to EnterCriticalSection

master
emekoi 2018-11-18 18:32:50 -06:00
parent aaae2f5705
commit 25d7f5b654
2 changed files with 6 additions and 9 deletions

View File

@ -77,12 +77,6 @@ const MutexWindows = struct {
}
};
fn initOsData(self: *MutexWindows) void {
if (self.lock == null) {
windows.InitializeCriticalSection(&self.lock);
}
}
pub fn init() Mutex {
return Mutex {
.lock = null,
@ -95,8 +89,11 @@ const MutexWindows = struct {
}
pub fn acquire(self: *Mutex) Held {
self.initOsData();
while (windows.TryEnterCriticalSection(&self.lock) == 0) {}
if (self.lock == null) {
windows.InitializeCriticalSection(&self.lock);
}
windows.EnterCriticalSection(&self.lock);
return Held { .mutex = self };
}
};

View File

@ -222,7 +222,7 @@ pub const FOREGROUND_RED = 4;
pub const FOREGROUND_INTENSITY = 8;
pub extern "kernel32" stdcallcc fn InitializeCriticalSection(lpCriticalSection: *?RTL_CRITICAL_SECTION) void;
pub extern "kernel32" stdcallcc fn TryEnterCriticalSection(lpCriticalSection: *?RTL_CRITICAL_SECTION) BOOL;
pub extern "kernel32" stdcallcc fn EnterCriticalSection(lpCriticalSection: *?RTL_CRITICAL_SECTION) void;
pub extern "kernel32" stdcallcc fn LeaveCriticalSection(lpCriticalSection: *?RTL_CRITICAL_SECTION) void;
pub extern "kernel32" stdcallcc fn DeleteCriticalSection(lpCriticalSection: *?RTL_CRITICAL_SECTION) void;