diff options
| author | emekoi <emekankurumeh@outlook.com> | 2018-11-27 16:20:09 +0000 |
|---|---|---|
| committer | emekoi <emekankurumeh@outlook.com> | 2019-01-11 09:56:36 -0600 |
| commit | 35d93d22db6f1cdf20011b0db84586107513b462 (patch) | |
| tree | 50a55d1cb60ed27bfad5566be98b75956125f1f4 /std/mutex.zig | |
| parent | 93851270526e71407b4225a23daa66214a4010f9 (diff) | |
| download | zig-35d93d22db6f1cdf20011b0db84586107513b462.tar.gz zig-35d93d22db6f1cdf20011b0db84586107513b462.zip | |
removed nullables
Diffstat (limited to 'std/mutex.zig')
| -rw-r--r-- | std/mutex.zig | 55 |
1 files changed, 24 insertions, 31 deletions
diff --git a/std/mutex.zig b/std/mutex.zig index 3469b9a118..30b68511ea 100644 --- a/std/mutex.zig +++ b/std/mutex.zig @@ -62,57 +62,50 @@ pub const Mutex = switch(builtin.os) { }, builtin.Os.windows => struct { - lock: ?windows.CRITICAL_SECTION, - init_once: windows.PINIT_ONCE, + lock: windows.CRITICAL_SECTION, + init_once: windows.RTL_RUN_ONCE, pub const Held = struct { mutex: *Mutex, pub fn release(self: Held) void { - if (self.mutex.lock) |*lock| { - windows.LeaveCriticalSection(lock); - } + windows.LeaveCriticalSection(&self.mutex.lock); } }; pub fn init() Mutex { - return Mutex { - .lock = null, + return Mutex { + .lock = undefined, .init_once = undefined, }; } - extern fn initCriticalSection(InitOnce: *windows.PINIT_ONCE, Parameter: ?windows.PVOID, Context: ?windows.PVOID) windows.BOOL { - if (Context) |ctx| { - var mutex = @ptrCast(*?windows.CRITICAL_SECTION, @alignCast(8, ctx)); - if (mutex.* == null) { - var lock: windows.CRITICAL_SECTION = undefined; - windows.InitializeCriticalSection(&lock); - mutex.* = lock; - } - return windows.TRUE; - } - return windows.FALSE; + extern fn initCriticalSection( + InitOnce: *windows.RTL_RUN_ONCE, + Parameter: ?windows.PVOID, + Context: ?windows.PVOID + ) windows.BOOL { + var lock = @ptrCast( + *windows.CRITICAL_SECTION, + @alignCast(@alignOf(*windows.CRITICAL_SECTION), ctx.?) + ); + windows.InitializeCriticalSection(lock); + return windows.TRUE; } pub fn deinit(self: *Mutex) void { - if (self.lock) |*lock| { - windows.DeleteCriticalSection(lock); - } + windows.DeleteCriticalSection(&self.lock); } pub fn acquire(self: *Mutex) Held { - if (self.lock) |*lock| { - windows.EnterCriticalSection(lock); - } else { - var mutex = @ptrCast(?windows.PVOID, self); - if (windows.InitOnceExecuteOnce(&self.init_once, initCriticalSection, null, mutex) == windows.TRUE) { - windows.EnterCriticalSection(&self.lock.?); - } else { - @panic("unable to initialize Mutex"); - } + if (windows.InitOnceExecuteOnce( + &self.init_once, + initCriticalSection, + null, @ptrCast(?windows.PVOID, self) + ) == windows.FALSE) { + unreachable; } - + windows.EnterCriticalSection(&self.lock); return Held { .mutex = self }; } }, |
