aboutsummaryrefslogtreecommitdiff
path: root/core/sys/posix
diff options
context:
space:
mode:
authorLaytan Laats <laytanlaats@hotmail.com>2024-10-30 15:07:56 +0100
committerLaytan Laats <laytanlaats@hotmail.com>2024-10-30 15:51:56 +0100
commitcc3c9bd87116ce8fcb018719a725a71a16eab3b5 (patch)
tree1a0eb282a5846ac537852399290ec0af8b76830c /core/sys/posix
parentf469bbb0049f618d09dd1dd962389c8306db6bbc (diff)
fix thread_unix for Darwin after pthread corrections in posix package
afed3ce removed the sys/unix package and moved over to sys/posix, it has new bindings for the pthread APIs but should have been equivalent (not). 8fb7182 used `CANCEL_ENABLE :: 0`, `CANCEL_DISABLE :: 1`, `CANCEL_DEFERRED :: 0`, `CANCEL_ASYNCHRONOUS :: 1` for Darwin, while the correct values are `1`, `0`, `2` and `0` respectively (same mistake was made for FreeBSD in that commit). What this meant is that the `pthread_setcanceltype(PTHREAD_CANCEL_ASYNCHRONOUS)` was not actually successful, but because the error wasn't checked it was assumed it was. It also meant `pthread_setcancelstate(PTHREAD_CANCEL_ENABLE)` would actually be setting `PTHREAD_CANCEL_DISABLE`. The code in this PR restores the behaviour by now actually deliberately setting `PTHREAD_CANCEL_DISABLE` and not setting `PTHREAD_CANCEL_ASYNCHRONOUS` which was the previous behaviour that does actually seem to work for some reason. (I also fixed an issue in fmt where `x` would use uppercase if it was a pointer.)
Diffstat (limited to 'core/sys/posix')
-rw-r--r--core/sys/posix/pthread.odin14
1 files changed, 12 insertions, 2 deletions
diff --git a/core/sys/posix/pthread.odin b/core/sys/posix/pthread.odin
index 9391a6359..490064da6 100644
--- a/core/sys/posix/pthread.odin
+++ b/core/sys/posix/pthread.odin
@@ -355,12 +355,16 @@ Thread_Scope :: enum c.int {
}
Cancel_State :: enum c.int {
+ // Cancel takes place at next cancellation point.
ENABLE = PTHREAD_CANCEL_ENABLE,
+ // Cancel postponed.
DISABLE = PTHREAD_CANCEL_DISABLE,
}
Cancel_Type :: enum c.int {
+ // Cancel waits until cancellation point.
DEFERRED = PTHREAD_CANCEL_DEFERRED,
+ // Cancel occurs immediately.
ASYNCHRONOUS = PTHREAD_CANCEL_ASYNCHRONOUS,
}
@@ -372,6 +376,12 @@ when ODIN_OS == .Darwin {
PTHREAD_CANCEL_DISABLE :: 0x00
PTHREAD_CANCEL_ENABLE :: 0x01
+ // PTHREAD_CANCEL_ASYNCHRONOUS :: 1
+ // PTHREAD_CANCEL_DEFERRED :: 0
+ //
+ // PTHREAD_CANCEL_DISABLE :: 1
+ // PTHREAD_CANCEL_ENABLE :: 0
+
PTHREAD_CANCELED :: rawptr(uintptr(1))
PTHREAD_CREATE_DETACHED :: 2
@@ -434,8 +444,8 @@ when ODIN_OS == .Darwin {
PTHREAD_PRIO_NONE :: 0
PTHREAD_PRIO_PROTECT :: 2
- PTHREAD_PROCESS_SHARED :: 0
- PTHREAD_PROCESS_PRIVATE :: 1
+ PTHREAD_PROCESS_SHARED :: 1
+ PTHREAD_PROCESS_PRIVATE :: 0
PTHREAD_SCOPE_PROCESS :: 0
PTHREAD_SCOPE_SYSTEM :: 2