authorgravatar for kbutcher6200@gmail.comkprotty <kbutcher6200@gmail.com> 2021-06-26 10:52:34-05:00
committergravatar for kbutcher6200@gmail.comkprotty <kbutcher6200@gmail.com> 2021-06-30 21:49:00-05:00
logc6fb968a3d702fbf8067164052ccf562f5e362ef
tree999e66ef1066e813c788df367e0ced2243b1ed94
parentfd4a607bb2f1a1cbf8b8c1fd5d35f5f775e79114

std.Thread: fix posix


1 files changed, 9 insertions(+), 4 deletions(-)

lib/std/Thread.zig+9-4
...@@ -376,11 +376,16 @@ const PosixThreadImpl = struct {...@@ -376,11 +376,16 @@ const PosixThreadImpl = struct {
376 fn spawn(config: SpawnConfig, comptime f: anytype, args: anytype) !Impl {376 fn spawn(config: SpawnConfig, comptime f: anytype, args: anytype) !Impl {
377 const Args = @TypeOf(args);377 const Args = @TypeOf(args);
378 const allocator = std.heap.c_allocator;378 const allocator = std.heap.c_allocator;
379
379 const Instance = struct {380 const Instance = struct {
380 fn entryFn(raw_arg: ?*c_void) callconv(.C) ?*c_void {381 fn entryFn(raw_arg: ?*c_void) callconv(.C) ?*c_void {
381 const args_ptr = @ptrCast(*Args, @alignCast(@alignOf(Args), raw_arg orelse unreachable));382 if (@sizeOf(Args) < 1) {
382 defer allocator.destroy(args_ptr);383 return callFn(f, @as(Args, undefined));
383 return callFn(f, args_ptr.*);384 }
385
386 const args_ptr = @ptrCast(*Args, @alignCast(@alignOf(Args), raw_arg));
387 defer allocator.destroy(args_ptr);
388 return callFn(f, args_ptr.*);
384 }389 }
385 };390 };
386391
...@@ -402,7 +407,7 @@ const PosixThreadImpl = struct {...@@ -402,7 +407,7 @@ const PosixThreadImpl = struct {
402 &handle,407 &handle,
403 &attr,408 &attr,
404 Instance.entryFn,409 Instance.entryFn,
405 @ptrCast(*c_void, args_ptr),410 if (@sizeOf(Args) > 1) @ptrCast(*c_void, args_ptr) else undefined,
406 )) {411 )) {
407 0 => return Impl{ .handle = handle },412 0 => return Impl{ .handle = handle },
408 os.EAGAIN => return error.SystemResources,413 os.EAGAIN => return error.SystemResources,