diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2020-01-03 09:50:12 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-01-03 09:50:12 +0000 |
| commit | d0ca0455869229b93425396c94be0d685107bded (patch) | |
| tree | 35d702accb1814dd412c2eda2ff26fb4e1e8c48c | |
| parent | 93ead4bcb33dd0592794b0acbc1ba6832d0a4f89 (diff) | |
| parent | 673879d1d2d87440195458474cc221d8dc2ef78c (diff) | |
Merge pull request #530 from KTRosenberg/unix_yield_sem_fix
Fixes for yielding and semaphore posting on unix
| -rw-r--r-- | .gitignore | 3 | ||||
| -rw-r--r-- | core/sync/sync_darwin.odin | 8 | ||||
| -rw-r--r-- | core/sync/sync_linux.odin | 5 | ||||
| -rw-r--r-- | core/sys/unix/pthread_linux.odin | 4 | ||||
| -rw-r--r-- | core/sys/unix/pthread_unix.odin | 3 | ||||
| -rw-r--r-- | core/thread/thread_unix.odin | 2 |
6 files changed, 18 insertions, 7 deletions
diff --git a/.gitignore b/.gitignore index b80ebb2dc..20e3578ca 100644 --- a/.gitignore +++ b/.gitignore @@ -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
\ No newline at end of file +*.sublime-workspace diff --git a/core/sync/sync_darwin.odin b/core/sync/sync_darwin.odin index 2c86e21db..8153b4b37 100644 --- a/core/sync/sync_darwin.odin +++ b/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) { diff --git a/core/sync/sync_linux.odin b/core/sync/sync_linux.odin index dc761f6aa..74f2b1e87 100644 --- a/core/sync/sync_linux.odin +++ b/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) { diff --git a/core/sys/unix/pthread_linux.odin b/core/sys/unix/pthread_linux.odin index 18ef09a69..09d27329c 100644 --- a/core/sys/unix/pthread_linux.odin +++ b/core/sys/unix/pthread_linux.odin @@ -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 ---; } diff --git a/core/sys/unix/pthread_unix.odin b/core/sys/unix/pthread_unix.odin index cd3b5c198..267bd28bc 100644 --- a/core/sys/unix/pthread_unix.odin +++ b/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") diff --git a/core/thread/thread_unix.odin b/core/thread/thread_unix.odin index dd8230ade..53b8790d7 100644 --- a/core/thread/thread_unix.odin +++ b/core/thread/thread_unix.odin @@ -158,5 +158,5 @@ destroy :: proc(t: ^Thread) { yield :: proc() { - unix.pthread_yield(); + unix.sched_yield(); } |