authorgravatar for kbutcher6200@gmail.comkprotty <kbutcher6200@gmail.com> 2021-06-22 11:27:58-05:00
committergravatar for kbutcher6200@gmail.comkprotty <kbutcher6200@gmail.com> 2021-06-30 21:49:00-05:00
log5f4a40e6aa7709fe708f9b20b32f63a50cc64736
tree00505cade6b7b5b5128ea64396c39fe910ebdfec
parentb1f37b4eade8bf5bc63ee048ebdb83c584dbe0ed

std.Thread: typo fixes 2


1 files changed, 101 insertions(+), 67 deletions(-)

lib/std/Thread.zig+101-67
...@@ -150,7 +150,7 @@ const Completion = Atomic(enum(u8) {...@@ -150,7 +150,7 @@ const Completion = Atomic(enum(u8) {
150150
151/// Used by the Thread implementations to call the spawned function with the arguments.151/// Used by the Thread implementations to call the spawned function with the arguments.
152fn callFn(comptime f: anytype, args: anytype) switch (Impl) {152fn callFn(comptime f: anytype, args: anytype) switch (Impl) {
153 WindowsThreadImpl => windows.DWORD,153 WindowsThreadImpl => std.os.windows.DWORD,
154 LinuxThreadImpl => u8,154 LinuxThreadImpl => u8,
155 PosixThreadImpl => ?*c_void,155 PosixThreadImpl => ?*c_void,
156 else => unreachable,156 else => unreachable,
...@@ -223,7 +223,7 @@ const WindowsThreadImpl = struct {...@@ -223,7 +223,7 @@ const WindowsThreadImpl = struct {
223223
224 fn free(self: ThreadCompletion) void {224 fn free(self: ThreadCompletion) void {
225 const status = windows.kernel32.HeapFree(self.heap_handle, 0, self.heap_ptr);225 const status = windows.kernel32.HeapFree(self.heap_handle, 0, self.heap_ptr);
226 assert(status == 0);226 assert(status != 0);
227 }227 }
228 };228 };
229229
...@@ -233,9 +233,9 @@ const WindowsThreadImpl = struct {...@@ -233,9 +233,9 @@ const WindowsThreadImpl = struct {
233 fn_args: Args,233 fn_args: Args,
234 thread: ThreadCompletion,234 thread: ThreadCompletion,
235235
236 fn entryFn(raw_ptr: *windows.PVOID) callconv(.C) windows.DWORD {236 fn entryFn(raw_ptr: windows.PVOID) callconv(.C) windows.DWORD {
237 const self = @ptrCast(*@This(), @alignCast(@alignOf(@This()), raw_ptr));237 const self = @ptrCast(*@This(), @alignCast(@alignOf(@This()), raw_ptr));
238 defer switch (self.thread.completion.swap(.completed, .Acquire)) {238 defer switch (self.thread.completion.swap(.completed, .SeqCst)) {
239 .running => {},239 .running => {},
240 .completed => unreachable,240 .completed => unreachable,
241 .detached => self.thread.free(),241 .detached => self.thread.free(),
...@@ -269,7 +269,7 @@ const WindowsThreadImpl = struct {...@@ -269,7 +269,7 @@ const WindowsThreadImpl = struct {
269 instance.thread.thread_handle = windows.kernel32.CreateThread(269 instance.thread.thread_handle = windows.kernel32.CreateThread(
270 null, 270 null,
271 stack_size, 271 stack_size,
272 Instance.entry, 272 Instance.entryFn,
273 @ptrCast(*c_void, instance), 273 @ptrCast(*c_void, instance),
274 0, 274 0,
275 null,275 null,
...@@ -277,7 +277,7 @@ const WindowsThreadImpl = struct {...@@ -277,7 +277,7 @@ const WindowsThreadImpl = struct {
277 return windows.unexpectedError(windows.kernel32.GetLastError());277 return windows.unexpectedError(windows.kernel32.GetLastError());
278 };278 };
279279
280 return .{ .thread = &instance.thread };280 return Impl{ .thread = &instance.thread };
281 }281 }
282282
283 fn getHandle(self: Impl) ThreadHandle {283 fn getHandle(self: Impl) ThreadHandle {
...@@ -286,7 +286,7 @@ const WindowsThreadImpl = struct {...@@ -286,7 +286,7 @@ const WindowsThreadImpl = struct {
286286
287 fn detach(self: Impl) void {287 fn detach(self: Impl) void {
288 windows.CloseHandle(self.thread.thread_handle);288 windows.CloseHandle(self.thread.thread_handle);
289 switch (self.thread.completion.swap(.detached, .AcqRel)) {289 switch (self.thread.completion.swap(.detached, .SeqCst)) {
290 .running => {},290 .running => {},
291 .completed => self.thread.free(),291 .completed => self.thread.free(),
292 .detached => unreachable,292 .detached => unreachable,
...@@ -296,6 +296,7 @@ const WindowsThreadImpl = struct {...@@ -296,6 +296,7 @@ const WindowsThreadImpl = struct {
296 fn join(self: Impl) void {296 fn join(self: Impl) void {
297 windows.WaitForSingleObjectEx(self.thread.thread_handle, windows.INFINITE, false) catch unreachable;297 windows.WaitForSingleObjectEx(self.thread.thread_handle, windows.INFINITE, false) catch unreachable;
298 windows.CloseHandle(self.thread.thread_handle);298 windows.CloseHandle(self.thread.thread_handle);
299 assert(self.thread.completion.load(.SeqCst) == .completed);
299 self.thread.free();300 self.thread.free();
300 } 301 }
301};302};
...@@ -625,67 +626,100 @@ const LinuxThreadImpl = struct {...@@ -625,67 +626,100 @@ const LinuxThreadImpl = struct {
625 }626 }
626627
627 // Calls `munmap(ptr, len)` then `exit(1)` without touching the stack (which lives in `ptr`).628 // Calls `munmap(ptr, len)` then `exit(1)` without touching the stack (which lives in `ptr`).
628 // Ported over from musl libc's pthread detached implementation.629 // Ported over from musl libc's pthread detached implementation (`__unmapself`).
629 extern fn __unmap_and_exit(ptr: usize, len: usize) callconv(.C) noreturn;630 extern fn __unmap_and_exit(ptr: usize, len: usize) callconv(.C) noreturn;
630 comptime {631 comptime {
631 asm(switch (target.cpu.arch) {632 if (target.os.tag == .linux) {
632 .i386 => (633 asm(switch (target.cpu.arch) {
633 \\.text634 .i386 => (
634 \\.global __unmap_and_exit635 \\.text
635 \\.type __unmap_and_exit, @function636 \\.global __unmap_and_exit
636 \\__unmap_and_exit:637 \\.type __unmap_and_exit, @function
637 \\ movl $91, %eax638 \\__unmap_and_exit:
638 \\ movl 4(%esp), %ebx639 \\ movl $91, %eax
639 \\ movl 8(%esp), %ecx640 \\ movl 4(%esp), %ebx
640 \\ int $128641 \\ movl 8(%esp), %ecx
641 \\ xorl %ebx, %ebx642 \\ int $128
642 \\ movl $1, %eax643 \\ xorl %ebx, %ebx
643 \\ int $128644 \\ movl $1, %eax
644 ),645 \\ int $128
645 .x86_64 => (646 ),
646 \\.text647 .x86_64 => (
647 \\.global __unmap_and_exit648 \\.text
648 \\.type __unmap_and_exit, @function649 \\.global __unmap_and_exit
649 \\__unmap_and_exit:650 \\.type __unmap_and_exit, @function
650 \\ movl $11, %eax651 \\__unmap_and_exit:
651 \\ syscall652 \\ movl $11, %eax
652 \\ xor %rdi, %rdi653 \\ syscall
653 \\ movl $60, %eax654 \\ xor %rdi, %rdi
654 \\ syscall655 \\ movl $60, %eax
655 ),656 \\ syscall
656 .arm, .armeb, .aarch64, .aarch64_be, .aarch64_32 => (657 ),
657 \\.text658 .arm, .armeb, .thumb, .thumb_eb => (
658 \\.global __unmap_and_exit659 \\.syntax unified
659 \\.type __unmap_and_exit, @function660 \\.text
660 \\__unmap_and_exit:661 \\.global __unmap_and_exit
661 \\ mov r7, #91662 \\.type __unmap_and_exit, %function
662 \\ svc 0663 \\__unmap_and_exit:
663 \\ mov r7, #1664 \\ mov r7, #91
664 \\ svc 0665 \\ svc 0
665 ),666 \\ mov r7, #1
666 .mips, .mipsel, .mips64, .mips64el => (667 \\ svc 0
667 \\.set noreorder668 ),
668 \\.global __unmap_and_exit669 .aarch64, .aarch64_be, .aarch64_32 => (
669 \\.type __unmap_and_exit, @function670 \\.global __unmap_and_exit
670 \\__unmap_and_exit:671 \\.type __unmap_and_exit, %function
671 \\ li $2, 4091672 \\__unmap_and_exit:
672 \\ syscall673 \\ mov x8, #215
673 \\ li $4, 0674 \\ svc 0
674 \\ li $2, 4001675 \\ mov x8, #93
675 \\ syscall676 \\ svc 0
676 ),677 ),
677 .powerpc, .powerpc64, .powerpc64le => (678 .mips, .mipsel, => (
678 \\.text679 \\.set noreorder
679 \\.global __unmap_and_exit680 \\.global __unmap_and_exit
680 \\.type __unmap_and_exit, @function681 \\.type __unmap_and_exit,@function
681 \\__unmap_and_exit:682 \\__unmap_and_exit:
682 \\ li 0, 91683 \\ move $sp, $25
683 \\ sc684 \\ li $2, 4091
684 \\ li 0, 1685 \\ syscall
685 \\ sc686 \\ li $4, 0
686 \\ blr687 \\ li $2, 4001
687 ),688 \\ syscall
688 else => @compileError("Platform not supported"),689 ),
689 });690 .mips64, .mips64el => (
691 \\.set noreorder
692 \\.global __unmap_and_exit
693 \\.type __unmap_and_exit, @function
694 \\__unmap_and_exit:
695 \\ li $2, 4091
696 \\ syscall
697 \\ li $4, 0
698 \\ li $2, 4001
699 \\ syscall
700 ),
701 .powerpc, .powerpc64, .powerpc64le => (
702 \\.text
703 \\.global __unmap_and_exit
704 \\.type __unmap_and_exit, %function
705 \\__unmap_and_exit:
706 \\ li 0, 91
707 \\ sc
708 \\ li 0, 1
709 \\ sc
710 \\ blr
711 ),
712 .riscv64 => (
713 \\.global __unmap_and_exit
714 \\.type __unmap_and_exit, %function
715 \\__unmap_and_exit:
716 \\ li a7, 215
717 \\ ecall
718 \\ li a7, 93
719 \\ ecall
720 ),
721 else => @compileError("Platform not supported"),
722 });
723 }
690 }724 }
691};725};
\ No newline at end of file