| author | |
| committer | |
| log | 25d7f5b65475d087ee1f046a364f8a9e6cd60135 |
| tree | 34b817b0876cbb9e9ba4575a398d0415b777827e |
| parent | aaae2f5705a2dee3a12ea49c1094c217a73bb897 |
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 | }; |
| 79 | 79 | ||
| 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 | } |
| 96 | 90 | ||
| 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; |
| 222 | pub const FOREGROUND_INTENSITY = 8; | 222 | pub const FOREGROUND_INTENSITY = 8; |
| 223 | 223 | ||
| 224 | pub extern "kernel32" stdcallcc fn InitializeCriticalSection(lpCriticalSection: *?RTL_CRITICAL_SECTION) void; | 224 | pub extern "kernel32" stdcallcc fn InitializeCriticalSection(lpCriticalSection: *?RTL_CRITICAL_SECTION) void; |
| 225 | pub extern "kernel32" stdcallcc fn TryEnterCriticalSection(lpCriticalSection: *?RTL_CRITICAL_SECTION) BOOL; | 225 | pub extern "kernel32" stdcallcc fn EnterCriticalSection(lpCriticalSection: *?RTL_CRITICAL_SECTION) void; |
| 226 | pub extern "kernel32" stdcallcc fn LeaveCriticalSection(lpCriticalSection: *?RTL_CRITICAL_SECTION) void; | 226 | pub extern "kernel32" stdcallcc fn LeaveCriticalSection(lpCriticalSection: *?RTL_CRITICAL_SECTION) void; |
| 227 | pub extern "kernel32" stdcallcc fn DeleteCriticalSection(lpCriticalSection: *?RTL_CRITICAL_SECTION) void; | 227 | pub extern "kernel32" stdcallcc fn DeleteCriticalSection(lpCriticalSection: *?RTL_CRITICAL_SECTION) void; |
| 228 | 228 |