authorgravatar for emekankurumeh@outlook.comemekoi <emekankurumeh@outlook.com> 2018-11-18 18:32:50-06:00
committergravatar for emekankurumeh@outlook.comemekoi <emekankurumeh@outlook.com> 2019-01-11 09:56:34-06:00
log25d7f5b65475d087ee1f046a364f8a9e6cd60135
tree34b817b0876cbb9e9ba4575a398d0415b777827e
parentaaae2f5705a2dee3a12ea49c1094c217a73bb897

switching back to EnterCriticalSection


2 files changed, 6 insertions(+), 9 deletions(-)

std/mutex.zig+5-8
...@@ -77,12 +77,6 @@ const MutexWindows = struct {...@@ -77,12 +77,6 @@ const MutexWindows = struct {
77 }77 }
78 };78 };
7979
80 fn initOsData(self: *MutexWindows) void {
81 if (self.lock == null) {
82 windows.InitializeCriticalSection(&self.lock);
83 }
84 }
85
86 pub fn init() Mutex {80 pub fn init() Mutex {
87 return Mutex {81 return Mutex {
88 .lock = null,82 .lock = null,
...@@ -95,8 +89,11 @@ const MutexWindows = struct {...@@ -95,8 +89,11 @@ const MutexWindows = struct {
95 }89 }
9690
97 pub fn acquire(self: *Mutex) Held {91 pub fn acquire(self: *Mutex) Held {
98 self.initOsData();92 if (self.lock == null) {
99 while (windows.TryEnterCriticalSection(&self.lock) == 0) {}93 windows.InitializeCriticalSection(&self.lock);
94 }
95
96 windows.EnterCriticalSection(&self.lock);
100 return Held { .mutex = self };97 return Held { .mutex = self };
101 }98 }
102};99};
std/os/windows/kernel32.zig+1-1
...@@ -222,7 +222,7 @@ pub const FOREGROUND_RED = 4;...@@ -222,7 +222,7 @@ pub const FOREGROUND_RED = 4;
222pub const FOREGROUND_INTENSITY = 8;222pub const FOREGROUND_INTENSITY = 8;
223223
224pub extern "kernel32" stdcallcc fn InitializeCriticalSection(lpCriticalSection: *?RTL_CRITICAL_SECTION) void;224pub extern "kernel32" stdcallcc fn InitializeCriticalSection(lpCriticalSection: *?RTL_CRITICAL_SECTION) void;
225pub extern "kernel32" stdcallcc fn TryEnterCriticalSection(lpCriticalSection: *?RTL_CRITICAL_SECTION) BOOL; 225pub extern "kernel32" stdcallcc fn EnterCriticalSection(lpCriticalSection: *?RTL_CRITICAL_SECTION) void;
226pub extern "kernel32" stdcallcc fn LeaveCriticalSection(lpCriticalSection: *?RTL_CRITICAL_SECTION) void; 226pub extern "kernel32" stdcallcc fn LeaveCriticalSection(lpCriticalSection: *?RTL_CRITICAL_SECTION) void;
227pub extern "kernel32" stdcallcc fn DeleteCriticalSection(lpCriticalSection: *?RTL_CRITICAL_SECTION) void; 227pub extern "kernel32" stdcallcc fn DeleteCriticalSection(lpCriticalSection: *?RTL_CRITICAL_SECTION) void;
228228