From 759acdb938d4d69c37a6c402b5ecfdedd3ba2bee Mon Sep 17 00:00:00 2001 From: Gunnar Beutner Date: Mon, 10 May 2021 15:13:59 +0200 Subject: [PATCH] LibC: Partially implement pthread_setcancel{state,type}() With those partially implemented I can start to clone the SerenityOS git repository via HTTPS. The download still fails half-way through because SSL_read returns an error for reasons I haven't investigated yet. --- Userland/Libraries/LibPthread/pthread.cpp | 18 ++++++++++++++---- Userland/Libraries/LibPthread/pthread.h | 3 +++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibPthread/pthread.cpp b/Userland/Libraries/LibPthread/pthread.cpp index 44fa5ab045..f4136524ce 100644 --- a/Userland/Libraries/LibPthread/pthread.cpp +++ b/Userland/Libraries/LibPthread/pthread.cpp @@ -555,14 +555,24 @@ int pthread_getname_np(pthread_t thread, char* buffer, size_t buffer_size) __RETURN_PTHREAD_ERROR(rc); } -int pthread_setcancelstate([[maybe_unused]] int state, [[maybe_unused]] int* oldstate) +int pthread_setcancelstate(int state, int* oldstate) { - TODO(); + if (oldstate) + *oldstate = PTHREAD_CANCEL_DISABLE; + dbgln("FIXME: Implement pthread_setcancelstate({}, ...)", state); + if (state != PTHREAD_CANCEL_DISABLE) + return EINVAL; + return 0; } -int pthread_setcanceltype([[maybe_unused]] int type, [[maybe_unused]] int* oldtype) +int pthread_setcanceltype(int type, int* oldtype) { - TODO(); + if (oldtype) + *oldtype = PTHREAD_CANCEL_DEFERRED; + dbgln("FIXME: Implement pthread_setcanceltype({}, ...)", type); + if (type != PTHREAD_CANCEL_DEFERRED) + return EINVAL; + return 0; } constexpr static pid_t spinlock_unlock_sentinel = 0; diff --git a/Userland/Libraries/LibPthread/pthread.h b/Userland/Libraries/LibPthread/pthread.h index 3a0e0d6ecb..220bc94c2d 100644 --- a/Userland/Libraries/LibPthread/pthread.h +++ b/Userland/Libraries/LibPthread/pthread.h @@ -97,6 +97,9 @@ int pthread_cond_timedwait(pthread_cond_t*, pthread_mutex_t*, const struct times #define PTHREAD_CANCEL_ENABLE 1 #define PTHREAD_CANCEL_DISABLE 2 +#define PTHREAD_CANCEL_DEFERRED 1 +#define PTHREAD_CANCEL_ASYNCHRONOUS 2 + int pthread_cancel(pthread_t); int pthread_setcancelstate(int state, int* oldstate); int pthread_setcanceltype(int type, int* oldtype);