diff options
author | Tim Schumacher <timschumi@gmx.de> | 2022-06-12 11:21:05 +0200 |
---|---|---|
committer | Brian Gianforcaro <b.gianfo@gmail.com> | 2022-07-22 10:07:15 -0700 |
commit | b4a926735ad7cb43c71bdfb1718459e87d094295 (patch) | |
tree | 60f79a62529d7040e5be65c176fe03fb4cc2c303 /Userland/Libraries | |
parent | e79f0e2ee95f16bdc52001162f818ad4737f7807 (diff) | |
download | serenity-b4a926735ad7cb43c71bdfb1718459e87d094295.zip |
LibC: Implement `pthread_setcancel{state,type}`
Diffstat (limited to 'Userland/Libraries')
-rw-r--r-- | Userland/Libraries/LibC/pthread.cpp | 19 |
1 files changed, 11 insertions, 8 deletions
diff --git a/Userland/Libraries/LibC/pthread.cpp b/Userland/Libraries/LibC/pthread.cpp index bab67312d0..6aa9e2e5cf 100644 --- a/Userland/Libraries/LibC/pthread.cpp +++ b/Userland/Libraries/LibC/pthread.cpp @@ -38,6 +38,9 @@ static constexpr size_t highest_reasonable_stack_size = 8 * MiB; // That's the d __thread void* s_stack_location; __thread size_t s_stack_size; +__thread int s_thread_cancel_state = PTHREAD_CANCEL_ENABLE; +__thread int s_thread_cancel_type = PTHREAD_CANCEL_DEFERRED; + #define __RETURN_PTHREAD_ERROR(rc) \ return ((rc) < 0 ? -(rc) : 0) @@ -502,22 +505,22 @@ int pthread_getname_np(pthread_t thread, char* buffer, size_t buffer_size) // https://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_setcancelstate.html int pthread_setcancelstate(int state, int* oldstate) { - if (oldstate) - *oldstate = PTHREAD_CANCEL_DISABLE; - dbgln("FIXME: Implement pthread_setcancelstate({}, ...)", state); - if (state != PTHREAD_CANCEL_DISABLE) + if (state != PTHREAD_CANCEL_ENABLE && state != PTHREAD_CANCEL_DISABLE) return EINVAL; + if (oldstate) + *oldstate = s_thread_cancel_state; + s_thread_cancel_state = state; return 0; } // https://pubs.opengroup.org/onlinepubs/009695399/functions/pthread_setcanceltype.html int pthread_setcanceltype(int type, int* oldtype) { - if (oldtype) - *oldtype = PTHREAD_CANCEL_DEFERRED; - dbgln("FIXME: Implement pthread_setcanceltype({}, ...)", type); - if (type != PTHREAD_CANCEL_DEFERRED) + if (type != PTHREAD_CANCEL_DEFERRED && type != PTHREAD_CANCEL_ASYNCHRONOUS) return EINVAL; + if (oldtype) + *oldtype = s_thread_cancel_type; + s_thread_cancel_type = type; return 0; } |