Selaa lähdekoodia

Update usage of `syscall` to use the intrinsics

gingerBill 4 vuotta sitten
vanhempi
commit
7c108dbf48
3 muutettua tiedostoa jossa 10 lisäystä ja 19 poistoa
  1. 2 2
      core/os/os_linux.odin
  2. 6 10
      core/sync/sync_freebsd.odin
  3. 2 7
      core/sync/sync_linux.odin

+ 2 - 2
core/os/os_linux.odin

@@ -7,6 +7,7 @@ import "core:runtime"
 import "core:strings"
 import "core:c"
 import "core:strconv"
+import "core:intrinsics"
 
 Handle    :: distinct i32;
 File_Time :: distinct u64;
@@ -269,7 +270,6 @@ SYS_GETTID: Syscall : 186;
 
 foreign libc {
 	@(link_name="__errno_location") __errno_location    :: proc() -> ^int ---;
-	@(link_name="syscall")          syscall             :: proc(number: Syscall, #c_vararg args: ..any) -> i32 ---;
 
 	@(link_name="open")             _unix_open          :: proc(path: cstring, flags: c.int, mode: c.int) -> Handle ---;
 	@(link_name="close")            _unix_close         :: proc(fd: Handle) -> c.int ---;
@@ -595,7 +595,7 @@ exit :: proc "contextless" (code: int) -> ! {
 }
 
 current_thread_id :: proc "contextless" () -> int {
-	return cast(int)syscall(SYS_GETTID);
+	return cast(int)intrinsics.syscall(SYS_GETTID);
 }
 
 dlopen :: proc(filename: string, flags: int) -> rawptr {

+ 6 - 10
core/sync/sync_freebsd.odin

@@ -1,16 +1,12 @@
 package sync
 
 import "core:sys/unix"
+import "core:intrinsics"
 
-foreign import libc "system:c"
 
 current_thread_id :: proc "contextless" () -> int {
-	foreign libc {
-		syscall :: proc(number: i32, #c_vararg args: ..any) -> i32 ---
-	}
-
 	SYS_GETTID :: 186;
-	return int(syscall(SYS_GETTID));
+	return int(intrinsics.syscall(SYS_GETTID));
 }
 
 
@@ -32,10 +28,10 @@ semaphore_destroy :: proc(s: ^Semaphore) {
 }
 
 semaphore_post :: proc(s: ^Semaphore, count := 1) {
-    // NOTE: SPEED: If there's one syscall to do this, we should use it instead of the loop.
-    for in 0..<count {
-	    assert(unix.sem_post(&s.handle) == 0);
-    }
+	// NOTE: SPEED: If there's one syscall to do this, we should use it instead of the loop.
+	for in 0..<count {
+		assert(unix.sem_post(&s.handle) == 0);
+	}
 }
 
 semaphore_wait_for :: proc(s: ^Semaphore) {

+ 2 - 7
core/sync/sync_linux.odin

@@ -1,16 +1,11 @@
 package sync
 
 import "core:sys/unix"
-
-foreign import libc "system:c"
+import "core:intrinsics"
 
 current_thread_id :: proc "contextless" () -> int {
-	foreign libc {
-		syscall :: proc(number: i32, #c_vararg args: ..any) -> i32 ---
-	}
-
 	SYS_GETTID :: 186;
-	return int(syscall(SYS_GETTID));
+	return int(intrinsics.syscall(SYS_GETTID));
 }