switch sh port's __unmapself to generic version when running on sh2/nommu
[musl] / src / thread / pthread_create.c
index 33808ce..6e2e481 100644 (file)
@@ -17,6 +17,7 @@ weak_alias(dummy_0, __acquire_ptc);
 weak_alias(dummy_0, __release_ptc);
 weak_alias(dummy_0, __pthread_tsd_run_dtors);
 weak_alias(dummy_0, __do_orphaned_stdio_locks);
+weak_alias(dummy_0, __dl_thread_cleanup);
 
 _Noreturn void __pthread_exit(void *result)
 {
@@ -66,12 +67,6 @@ _Noreturn void __pthread_exit(void *result)
                exit(0);
        }
 
-       if (self->locale != &libc.global_locale) {
-               a_dec(&libc.uselocale_cnt);
-               if (self->locale->ctype_utf8)
-                       a_dec(&libc.bytelocale_cnt_minus_1);
-       }
-
        /* Process robust list in userspace to handle non-pshared mutexes
         * and the detached thread case where the robust list head will
         * be invalid when the kernel would process it. */
@@ -92,6 +87,7 @@ _Noreturn void __pthread_exit(void *result)
        __vm_unlock();
 
        __do_orphaned_stdio_locks();
+       __dl_thread_cleanup();
 
        if (self->detached && self->map_base) {
                /* Detached threads must avoid the kernel clear_child_tid
@@ -122,7 +118,6 @@ _Noreturn void __pthread_exit(void *result)
 
 void __do_cleanup_push(struct __ptcb *cb)
 {
-       if (!libc.has_thread_pointer) return;
        struct pthread *self = __pthread_self();
        cb->__next = self->cancelbuf;
        self->cancelbuf = cb;
@@ -130,7 +125,6 @@ void __do_cleanup_push(struct __ptcb *cb)
 
 void __do_cleanup_pop(struct __ptcb *cb)
 {
-       if (!libc.has_thread_pointer) return;
        __pthread_self()->cancelbuf = cb->__next;
 }
 
@@ -197,8 +191,9 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att
        if (!libc.can_do_threads) return ENOSYS;
        self = __pthread_self();
        if (!libc.threaded) {
-               for (FILE *f=libc.ofl_head; f; f=f->next)
+               for (FILE *f=*__ofl_lock(); f; f=f->next)
                        init_file_lock(f);
+               __ofl_unlock();
                init_file_lock(__stdin_used);
                init_file_lock(__stdout_used);
                init_file_lock(__stderr_used);
@@ -272,7 +267,7 @@ int __pthread_create(pthread_t *restrict res, const pthread_attr_t *restrict att
        }
        new->robust_list.head = &new->robust_list.head;
        new->unblock_cancel = self->cancel;
-       new->canary = self->canary;
+       new->CANARY = self->CANARY;
 
        a_inc(&libc.threads_minus_1);
        ret = __clone((c11 ? start_c11 : start), stack, flags, new, &new->tid, TP_ADJ(new), &new->tid);