authorgravatar for emekankurumeh@outlook.comemekoi <emekankurumeh@outlook.com> 2018-11-27 16:20:09+00:00
committergravatar for emekankurumeh@outlook.comemekoi <emekankurumeh@outlook.com> 2019-01-11 09:56:36-06:00
log35d93d22db6f1cdf20011b0db84586107513b462
tree50a55d1cb60ed27bfad5566be98b75956125f1f4
parent93851270526e71407b4225a23daa66214a4010f9

removed nullables


2 files changed, 29 insertions(+), 38 deletions(-)

std/mutex.zig+24-31
...@@ -62,57 +62,50 @@ pub const Mutex = switch(builtin.os) {...@@ -62,57 +62,50 @@ pub const Mutex = switch(builtin.os) {
62 },62 },
63 builtin.Os.windows => struct {63 builtin.Os.windows => struct {
6464
65 lock: ?windows.CRITICAL_SECTION,65 lock: windows.CRITICAL_SECTION,
66 init_once: windows.PINIT_ONCE,66 init_once: windows.RTL_RUN_ONCE,
6767
68 pub const Held = struct {68 pub const Held = struct {
69 mutex: *Mutex,69 mutex: *Mutex,
7070
71 pub fn release(self: Held) void {71 pub fn release(self: Held) void {
72 if (self.mutex.lock) |*lock| {72 windows.LeaveCriticalSection(&self.mutex.lock);
73 windows.LeaveCriticalSection(lock);
74 }
75 }73 }
76 };74 };
7775
78 pub fn init() Mutex {76 pub fn init() Mutex {
79 return Mutex { 77 return Mutex {
80 .lock = null,78 .lock = undefined,
81 .init_once = undefined,79 .init_once = undefined,
82 };80 };
83 }81 }
8482
85 extern fn initCriticalSection(InitOnce: *windows.PINIT_ONCE, Parameter: ?windows.PVOID, Context: ?windows.PVOID) windows.BOOL {83 extern fn initCriticalSection(
86 if (Context) |ctx| {84 InitOnce: *windows.RTL_RUN_ONCE,
87 var mutex = @ptrCast(*?windows.CRITICAL_SECTION, @alignCast(8, ctx));85 Parameter: ?windows.PVOID,
88 if (mutex.* == null) {86 Context: ?windows.PVOID
89 var lock: windows.CRITICAL_SECTION = undefined;87 ) windows.BOOL {
90 windows.InitializeCriticalSection(&lock);88 var lock = @ptrCast(
91 mutex.* = lock;89 *windows.CRITICAL_SECTION,
92 }90 @alignCast(@alignOf(*windows.CRITICAL_SECTION), ctx.?)
93 return windows.TRUE;91 );
94 }92 windows.InitializeCriticalSection(lock);
95 return windows.FALSE;93 return windows.TRUE;
96 }94 }
9795
98 pub fn deinit(self: *Mutex) void {96 pub fn deinit(self: *Mutex) void {
99 if (self.lock) |*lock| {97 windows.DeleteCriticalSection(&self.lock);
100 windows.DeleteCriticalSection(lock);
101 }
102 }98 }
10399
104 pub fn acquire(self: *Mutex) Held {100 pub fn acquire(self: *Mutex) Held {
105 if (self.lock) |*lock| {101 if (windows.InitOnceExecuteOnce(
106 windows.EnterCriticalSection(lock);102 &self.init_once,
107 } else {103 initCriticalSection,
108 var mutex = @ptrCast(?windows.PVOID, self);104 null, @ptrCast(?windows.PVOID, self)
109 if (windows.InitOnceExecuteOnce(&self.init_once, initCriticalSection, null, mutex) == windows.TRUE) {105 ) == windows.FALSE) {
110 windows.EnterCriticalSection(&self.lock.?);106 unreachable;
111 } else {
112 @panic("unable to initialize Mutex");
113 }
114 }107 }
115108 windows.EnterCriticalSection(&self.lock);
116 return Held { .mutex = self };109 return Held { .mutex = self };
117 }110 }
118 },111 },
std/os/windows/kernel32.zig+5-7
...@@ -222,9 +222,9 @@ pub const FOREGROUND_RED = 4;...@@ -222,9 +222,9 @@ pub const FOREGROUND_RED = 4;
222pub const FOREGROUND_INTENSITY = 8;222pub const FOREGROUND_INTENSITY = 8;
223223
224pub extern "kernel32" stdcallcc fn InitializeCriticalSection(lpCriticalSection: *CRITICAL_SECTION) void;224pub extern "kernel32" stdcallcc fn InitializeCriticalSection(lpCriticalSection: *CRITICAL_SECTION) void;
225pub extern "kernel32" stdcallcc fn EnterCriticalSection(lpCriticalSection: *CRITICAL_SECTION) void; 225pub extern "kernel32" stdcallcc fn EnterCriticalSection(lpCriticalSection: *CRITICAL_SECTION) void;
226pub extern "kernel32" stdcallcc fn LeaveCriticalSection(lpCriticalSection: *CRITICAL_SECTION) void; 226pub extern "kernel32" stdcallcc fn LeaveCriticalSection(lpCriticalSection: *CRITICAL_SECTION) void;
227pub extern "kernel32" stdcallcc fn DeleteCriticalSection(lpCriticalSection: *CRITICAL_SECTION) void; 227pub extern "kernel32" stdcallcc fn DeleteCriticalSection(lpCriticalSection: *CRITICAL_SECTION) void;
228228
229pub const LIST_ENTRY = extern struct {229pub const LIST_ENTRY = extern struct {
230 Flink: *LIST_ENTRY,230 Flink: *LIST_ENTRY,
...@@ -254,12 +254,10 @@ pub const RTL_CRITICAL_SECTION = extern struct {...@@ -254,12 +254,10 @@ pub const RTL_CRITICAL_SECTION = extern struct {
254254
255pub const CRITICAL_SECTION = RTL_CRITICAL_SECTION;255pub const CRITICAL_SECTION = RTL_CRITICAL_SECTION;
256256
257pub extern "kernel32" stdcallcc fn InitOnceExecuteOnce(InitOnce: *PINIT_ONCE, InitFn: PINIT_ONCE_FN, Context: ?PVOID, Parameter: ?LPVOID) BOOL;257pub extern "kernel32" stdcallcc fn InitOnceExecuteOnce(InitOnce: *RTL_RUN_ONCE, InitFn: PINIT_ONCE_FN, Context: ?PVOID, Parameter: ?LPVOID) BOOL;
258258
259pub const PINIT_ONCE_FN = ?extern fn(InitOnce: *PINIT_ONCE, Parameter: ?PVOID, Context: ?PVOID) BOOL;259pub const PINIT_ONCE_FN = ?extern fn(InitOnce: *RTL_RUN_ONCE, Parameter: ?PVOID, Context: ?PVOID) BOOL;
260260
261pub const RTL_RUN_ONCE = extern struct {261pub const RTL_RUN_ONCE = extern struct {
262 Ptr: PVOID,262 Ptr: PVOID,
263};263};
264
265pub const PINIT_ONCE = RTL_RUN_ONCE;