Merge pull request #530 from KTRosenberg/unix_yield_sem_fix

Fixes for yielding and semaphore posting on unix
This commit is contained in:
gingerBill
2020-01-03 09:50:12 +00:00
committed by GitHub
6 changed files with 18 additions and 7 deletions

3
.gitignore vendored
View File

@@ -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

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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 ---;
}

View File

@@ -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")

View File

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