Ver código fonte

replaced pthread_yield with ssched_yield, fixed semaphore post:q

KTRosenberg 5 anos atrás
pai
commit
d017b5de9d

+ 5 - 3
core/sync/sync_darwin.odin

@@ -28,9 +28,11 @@ semaphore_destroy :: proc(s: ^Semaphore) {
 }
 
 semaphore_post :: proc(s: ^Semaphore, count := 1) {
-	assert(count == 1);
-	res := darwin.semaphore_signal(s.handle);
-	assert(res == 0);
+	// NOTE: SPEED: If there's one syscall to do this, we should use it instead of the loop.
+	for in 0..count-1 {
+		res := darwin.semaphore_signal(s.handle);
+		assert(res == 0);
+	}
 }
 
 semaphore_wait_for :: proc(s: ^Semaphore) {

+ 4 - 1
core/sync/sync_linux.odin

@@ -20,7 +20,10 @@ semaphore_destroy :: proc(s: ^Semaphore) {
 }
 
 semaphore_post :: proc(s: ^Semaphore, count := 1) {
-	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-1 {
+	    assert(unix.sem_post(&s.handle) == 0);
+    }
 }
 
 semaphore_wait_for :: proc(s: ^Semaphore) {

+ 2 - 0
core/sys/unix/pthread_linux.odin

@@ -103,4 +103,6 @@ foreign pthread {
 	sem_wait :: proc(sem: ^sem_t) -> c.int ---;
 	sem_trywait :: proc(sem: ^sem_t) -> c.int ---;
 	// sem_timedwait :: proc(sem: ^sem_t, timeout: time.TimeSpec) -> c.int ---;
+
+	pthread_yield :: proc() -> c.int ---;
 }

+ 2 - 1
core/sys/unix/pthread_unix.odin

@@ -52,7 +52,8 @@ foreign pthread {
 	pthread_attr_setstack :: proc(attrs: ^pthread_attr_t, stack_ptr: rawptr, stack_size: u64) -> c.int ---;
 	pthread_attr_getstack :: proc(attrs: ^pthread_attr_t, stack_ptr: ^rawptr, stack_size: ^u64) -> c.int ---;
 
-	pthread_yield :: proc() -> c.int ---;
+	sched_yield :: proc() -> c.int ---;
+	
 }
 
 @(default_calling_convention="c")

+ 1 - 1
core/thread/thread_unix.odin

@@ -158,5 +158,5 @@ destroy :: proc(t: ^Thread) {
 
 
 yield :: proc() {
-	unix.pthread_yield();
+	unix.sched_yield();
 }