Commit c2a8bc55 authored by jan.koester's avatar jan.koester
Browse files

Merge branch 'gtk-desktop': pthread_cancel (ENOSYS), pthread_cleanup_push/pop

parents 61c9c6d7 f285accf
Loading
Loading
Loading
Loading
+18 −2
Changes for include/pthread.h: 18 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -179,8 +179,8 @@ extern "C" {
   #define PTHREAD_CREATE_JOINABLE 0
   #define PTHREAD_CREATE_DETACHED 1

   /* Cancellation state/type (git's run-command.c, others): systempp has
    * no pthread_cancel(), so no thread is ever cancelled -- these only
   /* Cancellation state/type (git's run-command.c, others): systempp's
    * pthread_cancel() fails, so no thread is ever cancelled -- these only
    * keep and report the calling thread's settings. musl's/glibc's values. */
   #define PTHREAD_CANCEL_ENABLE       0
   #define PTHREAD_CANCEL_DISABLE      1
@@ -189,6 +189,22 @@ extern "C" {
   int pthread_setcancelstate(int state, int* oldstate);
   int pthread_setcanceltype(int type, int* oldtype);
   void pthread_testcancel(void);
   /* never cancels: returns ENOSYS (curl's resolver only uses it to stop
    * waiting for a getaddrinfo() thread it has already abandoned) */
   int pthread_cancel(pthread_t thread);

   /* Cleanup handlers (curl's resolver thread). With no cancellation they
    * only run through pthread_cleanup_pop(nonzero), not on pthread_exit().
    * The pair opens and closes a block, as POSIX allows. */
   struct __pthread_cleanup {
       void (*__routine)(void*);
       void* __arg;
   };
   #define pthread_cleanup_push(routine, arg) \
       do { struct __pthread_cleanup __pt_cb; \
            __pt_cb.__routine = (routine); __pt_cb.__arg = (arg); {
   #define pthread_cleanup_pop(execute) \
       } if (execute) __pt_cb.__routine(__pt_cb.__arg); } while (0)
   int pthread_attr_setdetachstate(pthread_attr_t* attr, int detachstate);
   int pthread_attr_getdetachstate(const pthread_attr_t* attr, int* detachstate);

+7 −1
Changes for src/linux/thread.cpp: 7 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -764,7 +764,7 @@ extern "C" {
        return 0;
    }

    /* No pthread_cancel(): the state/type are only remembered per thread */
    /* No cancellation (pthread_cancel() fails): the state/type are only remembered per thread */
    static thread_local int t_cancel_state = PTHREAD_CANCEL_ENABLE;
    static thread_local int t_cancel_type = PTHREAD_CANCEL_DEFERRED;

@@ -786,6 +786,12 @@ extern "C" {

    void pthread_testcancel(void) {}

    /* No thread cancellation: the request fails, the thread runs on */
    int pthread_cancel(pthread_t thread) {
        (void)thread;
        return ENOSYS;
    }

    int pthread_setspecific(pthread_key_t key, const void* tls) {
        if (key >= PTHREAD_KEYS_MAX) return EINVAL;
        sys::thread* self = sys::__internal::thread::getins().self();