Commit 5ada85d7 authored by jan.koester's avatar jan.koester
Browse files

pthread_setcancelstate/setcanceltype/testcancel; reverse() out of <stdlib.h>

git 2.56 needs both: run-command.c disables cancellation around its
async threads, and builtin/blame.c's "static int reverse" collided with
the internal itoa() helper declared in <stdlib.h>. There is no
pthread_cancel(), so the cancel state/type are only kept per thread.
reverse() stays exported for ABI compatibility.

Co-Authored-By: default avatarClaude Opus 5.5 <noreply@anthropic.com>
parent 49c47ef0
Loading
Loading
Loading
Loading
+11 −0
Changes for include/pthread.h: 11 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -178,6 +178,17 @@ extern "C" {
   /* glibc's values (OpenSSL's thread_posix.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
    * keep and report the calling thread's settings. musl's/glibc's values. */
   #define PTHREAD_CANCEL_ENABLE       0
   #define PTHREAD_CANCEL_DISABLE      1
   #define PTHREAD_CANCEL_DEFERRED     0
   #define PTHREAD_CANCEL_ASYNCHRONOUS 1
   int pthread_setcancelstate(int state, int* oldstate);
   int pthread_setcanceltype(int type, int* oldtype);
   void pthread_testcancel(void);
   int pthread_attr_setdetachstate(pthread_attr_t* attr, int detachstate);
   int pthread_attr_getdetachstate(const pthread_attr_t* attr, int* detachstate);

+0 −1
Changes for include/stdlib.h: 0 added lines, 1 removed line.
Original line number Diff line number Diff line
@@ -61,7 +61,6 @@ extern "C" {
    ldiv_t ldiv (long, long);
    lldiv_t lldiv (long long, long long);

    void reverse(char s[]);
    void itoa(int n, char s[]);
    void ltoa(long n, char s[]);
    void ftoa(float n, char s[]);
+22 −0
Changes for src/linux/thread.cpp: 22 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -764,6 +764,28 @@ extern "C" {
        return 0;
    }

    /* No pthread_cancel(): 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;

    int pthread_setcancelstate(int state, int* oldstate) {
        if (state != PTHREAD_CANCEL_ENABLE && state != PTHREAD_CANCEL_DISABLE)
            return EINVAL;
        if (oldstate) *oldstate = t_cancel_state;
        t_cancel_state = state;
        return 0;
    }

    int pthread_setcanceltype(int type, int* oldtype) {
        if (type != PTHREAD_CANCEL_DEFERRED && type != PTHREAD_CANCEL_ASYNCHRONOUS)
            return EINVAL;
        if (oldtype) *oldtype = t_cancel_type;
        t_cancel_type = type;
        return 0;
    }

    void pthread_testcancel(void) {}

    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();
+4 −0
Changes for src/stdlib.cpp: 4 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -532,6 +532,10 @@ extern "C" {
        return tldiv<lldiv_t,long long>(num,den); 
    }
       
    /* itoa()'s helper: still exported (ABI), no longer declared in
     * <stdlib.h> -- a public "reverse" clashed with programs' own (git's
     * builtin/blame.c: static int reverse) */
    void reverse(char s[]);
    void reverse(char s[]){
        int i, j;
        char c;