mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 07:38:48 +00:00
Merge pull request #530 from KTRosenberg/unix_yield_sem_fix
Fixes for yielding and semaphore posting on unix
This commit is contained in:
+2
-1
@@ -23,6 +23,7 @@ bld/
|
|||||||
.vs/
|
.vs/
|
||||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||||
#wwwroot/
|
#wwwroot/
|
||||||
|
demo
|
||||||
|
|
||||||
# MSTest test Results
|
# MSTest test Results
|
||||||
[Tt]est[Rr]esult*/
|
[Tt]est[Rr]esult*/
|
||||||
@@ -272,4 +273,4 @@ shared/
|
|||||||
*.bc
|
*.bc
|
||||||
*.ll
|
*.ll
|
||||||
|
|
||||||
*.sublime-workspace
|
*.sublime-workspace
|
||||||
|
|||||||
@@ -28,9 +28,11 @@ semaphore_destroy :: proc(s: ^Semaphore) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
semaphore_post :: proc(s: ^Semaphore, count := 1) {
|
semaphore_post :: proc(s: ^Semaphore, count := 1) {
|
||||||
assert(count == 1);
|
// NOTE: SPEED: If there's one syscall to do this, we should use it instead of the loop.
|
||||||
res := darwin.semaphore_signal(s.handle);
|
for in 0..count-1 {
|
||||||
assert(res == 0);
|
res := darwin.semaphore_signal(s.handle);
|
||||||
|
assert(res == 0);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
semaphore_wait_for :: proc(s: ^Semaphore) {
|
semaphore_wait_for :: proc(s: ^Semaphore) {
|
||||||
|
|||||||
@@ -20,7 +20,10 @@ semaphore_destroy :: proc(s: ^Semaphore) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
semaphore_post :: proc(s: ^Semaphore, count := 1) {
|
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) {
|
semaphore_wait_for :: proc(s: ^Semaphore) {
|
||||||
|
|||||||
@@ -103,4 +103,8 @@ foreign pthread {
|
|||||||
sem_wait :: proc(sem: ^sem_t) -> c.int ---;
|
sem_wait :: proc(sem: ^sem_t) -> c.int ---;
|
||||||
sem_trywait :: 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 ---;
|
// sem_timedwait :: proc(sem: ^sem_t, timeout: time.TimeSpec) -> c.int ---;
|
||||||
|
|
||||||
|
// NOTE: unclear whether pthread_yield is well-supported on Linux systems,
|
||||||
|
// see https://linux.die.net/man/3/pthread_yield
|
||||||
|
pthread_yield :: proc() -> c.int ---;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,7 +52,8 @@ foreign pthread {
|
|||||||
pthread_attr_setstack :: proc(attrs: ^pthread_attr_t, stack_ptr: rawptr, stack_size: u64) -> c.int ---;
|
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_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")
|
@(default_calling_convention="c")
|
||||||
|
|||||||
@@ -158,5 +158,5 @@ destroy :: proc(t: ^Thread) {
|
|||||||
|
|
||||||
|
|
||||||
yield :: proc() {
|
yield :: proc() {
|
||||||
unix.pthread_yield();
|
unix.sched_yield();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user