mirror of
https://github.com/odin-lang/Odin.git
synced 2026-06-05 18:24:06 +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:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -23,6 +23,7 @@ bld/
|
||||
.vs/
|
||||
# Uncomment if you have tasks that create the project's static files in wwwroot
|
||||
#wwwroot/
|
||||
demo
|
||||
|
||||
# MSTest test Results
|
||||
[Tt]est[Rr]esult*/
|
||||
@@ -272,4 +273,4 @@ shared/
|
||||
*.bc
|
||||
*.ll
|
||||
|
||||
*.sublime-workspace
|
||||
*.sublime-workspace
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -103,4 +103,8 @@ 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 ---;
|
||||
|
||||
// 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_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")
|
||||
|
||||
@@ -158,5 +158,5 @@ destroy :: proc(t: ^Thread) {
|
||||
|
||||
|
||||
yield :: proc() {
|
||||
unix.pthread_yield();
|
||||
unix.sched_yield();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user