Date: Sat, 20 Nov 2004 04:51:18 GMT From: David Xu <davidxu@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 65517 for review Message-ID: <200411200451.iAK4pIO4013131@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=65517 Change 65517 by davidxu@davidxu_alona on 2004/11/20 04:51:02 Use thread level lock, no kse sched level lock. Affected files ... .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_detach.c#2 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_exit.c#2 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_find_thread.c#2 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_getschedparam.c#2 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_join.c#2 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_setschedparam.c#2 edit .. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_stack.c#2 edit Differences ... ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_detach.c#2 (text+ko) ==== @@ -43,8 +43,8 @@ _pthread_detach(pthread_t pthread) { struct pthread *curthread = _get_curthread(); - struct kse_mailbox *kmbx = NULL; struct pthread *joiner; + long tid = -1; int rval = 0; /* Check for invalid calling parameters: */ @@ -64,36 +64,20 @@ rval = EINVAL; } else { /* Lock the detached thread: */ - THR_SCHED_LOCK(curthread, pthread); + THR_THREAD_LOCK(curthread, pthread); /* Flag the thread as detached: */ pthread->attr.flags |= PTHREAD_DETACHED; /* Retrieve any joining thread and remove it: */ joiner = pthread->joiner; - if ((joiner != NULL) && (joiner->kseg == pthread->kseg)) { - /* - * We already own the scheduler lock for the joiner. - * Take advantage of that and make the joiner runnable. - */ - if (joiner->join_status.thread == pthread) { - /* - * Set the return value for the woken thread: - */ - joiner->join_status.error = ESRCH; - joiner->join_status.ret = NULL; - joiner->join_status.thread = NULL; + THR_THREAD_UNLOCK(curthread, pthread); - kmbx = _thr_setrunnable_unlocked(joiner); - } - joiner = NULL; - } - THR_SCHED_UNLOCK(curthread, pthread); /* See if there is a thread waiting in pthread_join(): */ if ((joiner != NULL) && (_thr_ref_add(curthread, joiner, 0) == 0)) { /* Lock the joiner before fiddling with it. */ - THR_SCHED_LOCK(curthread, joiner); + THR_THREAD_LOCK(curthread, joiner); if (joiner->join_status.thread == pthread) { /* * Set the return value for the woken thread: @@ -102,14 +86,14 @@ joiner->join_status.ret = NULL; joiner->join_status.thread = NULL; - kmbx = _thr_setrunnable_unlocked(joiner); + tid = _thr_setrunnable_unlocked(joiner); } - THR_SCHED_UNLOCK(curthread, joiner); + THR_THREAD_UNLOCK(curthread, joiner); _thr_ref_delete(curthread, joiner); } _thr_ref_delete(curthread, pthread); - if (kmbx != NULL) - kse_wakeup(kmbx); + if (tid != -1) + thr_wake(tid); } /* Return the completion status: */ ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_exit.c#2 (text+ko) ==== @@ -86,8 +86,6 @@ _pthread_exit(void *status) { struct pthread *curthread = _get_curthread(); - kse_critical_t crit; - struct kse *curkse; /* Check if this thread is already in the process of exiting: */ if ((curthread->flags & THR_FLAGS_EXITING) != 0) { @@ -102,23 +100,10 @@ * Flag this thread as exiting. Threads should now be prevented * from joining to this thread. */ - THR_SCHED_LOCK(curthread, curthread); + THR_LOCK(curthread); curthread->flags |= THR_FLAGS_EXITING; - THR_SCHED_UNLOCK(curthread, curthread); + THR_UNLOCK(curthread); - /* - * To avoid signal-lost problem, if signals had already been - * delivered to us, handle it. we have already set EXITING flag - * so no new signals should be delivered to us. - * XXX this is not enough if signal was delivered just before - * thread called sigprocmask and masked it! in this case, we - * might have to re-post the signal by kill() if the signal - * is targeting process (not for a specified thread). - * Kernel has same signal-lost problem, a signal may be delivered - * to a thread which is on the way to call sigprocmask or thr_exit()! - */ - if (curthread->check_pending) - _thr_sig_check_pending(curthread); /* Save the return value: */ curthread->ret = status; while (curthread->cleanup != NULL) { @@ -132,24 +117,19 @@ /* Run the thread-specific data destructors: */ _thread_cleanupspecific(); } - if (!_kse_isthreaded()) + if (!_thr_isthreaded()) exit(0); - crit = _kse_critical_enter(); - curkse = _get_curkse(); - KSE_LOCK_ACQUIRE(curkse, &_thread_list_lock); + THR_LOCK_ACQUIRE(curthread, &_thread_list_lock); /* Use thread_list_lock */ _thread_active_threads--; - if ((_thread_scope_system <= 0 && _thread_active_threads == 1) || - (_thread_scope_system > 0 && _thread_active_threads == 0)) { - KSE_LOCK_RELEASE(curkse, &_thread_list_lock); - _kse_critical_leave(crit); + if (_thread_active_threads == 0) { + THR_LOCK_RELEASE(curthread, &_thread_list_lock); exit(0); /* Never reach! */ } - KSE_LOCK_RELEASE(curkse, &_thread_list_lock); + THR_LOCK_RELEASE(curthread, &_thread_list_lock); - /* This thread will never be re-scheduled. */ - KSE_LOCK(curkse); + THR_LOCK_SWITCH(curthread); THR_SET_STATE(curthread, PS_DEAD); _thr_sched_switch_unlocked(curthread); /* Never reach! */ ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_find_thread.c#2 (text+ko) ==== @@ -45,17 +45,13 @@ _thr_ref_add(struct pthread *curthread, struct pthread *thread, int include_dead) { - kse_critical_t crit; struct pthread *pthread; - struct kse *curkse; if (thread == NULL) /* Invalid thread: */ return (EINVAL); - crit = _kse_critical_enter(); - curkse = _get_curkse(); - KSE_LOCK_ACQUIRE(curkse, &_thread_list_lock); + THR_LOCK_ACQUIRE(curthread, &_thread_list_lock); pthread = _thr_hash_find(thread); if (pthread) { if ((include_dead == 0) && @@ -69,8 +65,7 @@ curthread->critical_count++; } } - KSE_LOCK_RELEASE(curkse, &_thread_list_lock); - _kse_critical_leave(crit); + THR_LOCK_RELEASE(curthread, &_thread_list_lock); /* Return zero if the thread exists: */ return ((pthread != NULL) ? 0 : ESRCH); @@ -79,20 +74,14 @@ void _thr_ref_delete(struct pthread *curthread, struct pthread *thread) { - kse_critical_t crit; - struct kse *curkse; - if (thread != NULL) { - crit = _kse_critical_enter(); - curkse = _get_curkse(); - KSE_LOCK_ACQUIRE(curkse, &_thread_list_lock); + THR_LOCK_ACQUIRE(curthread, &_thread_list_lock); thread->refcount--; if (curthread != NULL) curthread->critical_count--; if ((thread->refcount == 0) && (thread->tlflags & TLFLAGS_GC_SAFE) != 0) THR_GCLIST_ADD(thread); - KSE_LOCK_RELEASE(curkse, &_thread_list_lock); - _kse_critical_leave(crit); + THR_LOCK_RELEASE(curthread, &_thread_list_lock); } } ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_getschedparam.c#2 (text+ko) ==== @@ -52,22 +52,22 @@ * Avoid searching the thread list when it is the current * thread. */ - THR_SCHED_LOCK(curthread, curthread); + THR_THREAD_LOCK(curthread, curthread); param->sched_priority = THR_BASE_PRIORITY(pthread->base_priority); tmp = pthread->attr.sched_policy; - THR_SCHED_UNLOCK(curthread, curthread); + THR_THREAD_UNLOCK(curthread, curthread); *policy = tmp; ret = 0; } /* Find the thread in the list of active threads. */ else if ((ret = _thr_ref_add(curthread, pthread, /*include dead*/0)) == 0) { - THR_SCHED_LOCK(curthread, pthread); + THR_THREAD_LOCK(curthread, pthread); param->sched_priority = THR_BASE_PRIORITY(pthread->base_priority); tmp = pthread->attr.sched_policy; - THR_SCHED_UNLOCK(curthread, pthread); + THR_THREAD_UNLOCK(curthread, pthread); _thr_ref_delete(curthread, pthread); *policy = tmp; } ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_join.c#2 (text+ko) ==== @@ -42,7 +42,6 @@ { struct pthread *curthread = _get_curthread(); void *tmp; - kse_critical_t crit; int ret = 0; _thr_cancel_enter(curthread); @@ -71,10 +70,10 @@ return (ESRCH); } - THR_SCHED_LOCK(curthread, pthread); + THR_THREAD_LOCK(curthread, pthread); /* Check if this thread has been detached: */ if ((pthread->attr.flags & PTHREAD_DETACHED) != 0) { - THR_SCHED_UNLOCK(curthread, pthread); + THR_THREAD_UNLOCK(curthread, pthread); /* Remove the reference and return an error: */ _thr_ref_delete(curthread, pthread); ret = ESRCH; @@ -88,18 +87,16 @@ pthread->attr.flags |= PTHREAD_DETACHED; /* Unlock the thread. */ - THR_SCHED_UNLOCK(curthread, pthread); + THR_THREAD_UNLOCK(curthread, pthread); /* * Remove the thread from the list of active * threads and add it to the GC list. */ - crit = _kse_critical_enter(); - KSE_LOCK_ACQUIRE(curthread->kse, &_thread_list_lock); + THR_LOCK_ACQUIRE(curthread, &_thread_list_lock); THR_LIST_REMOVE(pthread); THR_GCLIST_ADD(pthread); - KSE_LOCK_RELEASE(curthread->kse, &_thread_list_lock); - _kse_critical_leave(crit); + THR_LOCK_RELEASE(curthread, &_thread_list_lock); /* Remove the reference. */ _thr_ref_delete(curthread, pthread); @@ -108,7 +105,7 @@ } else if (pthread->joiner != NULL) { /* Unlock the thread and remove the reference. */ - THR_SCHED_UNLOCK(curthread, pthread); + THR_THREAD_UNLOCK(curthread, pthread); _thr_ref_delete(curthread, pthread); /* Multiple joiners are not supported. */ @@ -122,25 +119,24 @@ curthread->join_status.thread = pthread; /* Unlock the thread and remove the reference. */ - THR_SCHED_UNLOCK(curthread, pthread); + THR_THREAD_UNLOCK(curthread, pthread); _thr_ref_delete(curthread, pthread); - THR_SCHED_LOCK(curthread, curthread); + THR_LOCK_SWITCH(curthread); while (curthread->join_status.thread == pthread) { THR_SET_STATE(curthread, PS_JOIN); - THR_SCHED_UNLOCK(curthread, curthread); /* Schedule the next thread: */ - _thr_sched_switch(curthread); - THR_SCHED_LOCK(curthread, curthread); + _thr_sched_switch_unlocked(curthread); + THR_LOCK_SWITCH(curthread); } - THR_SCHED_UNLOCK(curthread, curthread); + THR_UNLOCK_SWITCH(curthread); if ((curthread->cancelflags & THR_CANCELLING) && !(curthread->cancelflags & PTHREAD_CANCEL_DISABLE)) { if (_thr_ref_add(curthread, pthread, 1) == 0) { - THR_SCHED_LOCK(curthread, pthread); + THR_THREAD_LOCK(curthread, pthread); pthread->joiner = NULL; - THR_SCHED_UNLOCK(curthread, pthread); + THR_THREAD_UNLOCK(curthread, pthread); _thr_ref_delete(curthread, pthread); } pthread_exit(PTHREAD_CANCELED); ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_setschedparam.c#2 (text+ko) ==== @@ -63,11 +63,11 @@ * Lock the threads scheduling queue while we change * its priority: */ - THR_SCHED_LOCK(curthread, pthread); + THR_THREAD_LOCK(curthread, pthread); if ((pthread->state == PS_DEAD) || (pthread->state == PS_DEADLOCK) || ((pthread->flags & THR_FLAGS_EXITING) != 0)) { - THR_SCHED_UNLOCK(curthread, pthread); + THR_THREAD_UNLOCK(curthread, pthread); _thr_ref_delete(curthread, pthread); return (ESRCH); } @@ -82,7 +82,7 @@ * There is nothing to do; unlock the threads * scheduling queue. */ - THR_SCHED_UNLOCK(curthread, pthread); + THR_THREAD_UNLOCK(curthread, pthread); else { /* * Remove the thread from its current priority @@ -90,9 +90,9 @@ * active priority: */ old_prio = pthread->active_priority; - if ((pthread->flags & THR_FLAGS_IN_RUNQ) != 0) { + /* if ((pthread->flags & THR_FLAGS_IN_RUNQ) != 0) */ { in_readyq = 1; - THR_RUNQ_REMOVE(pthread); + /* THR_RUNQ_REMOVE(pthread); */ } /* Set the thread base priority: */ @@ -114,14 +114,14 @@ * its priority if it owns any priority * protection or inheritence mutexes. */ - THR_RUNQ_INSERT_HEAD(pthread); + /* THR_RUNQ_INSERT_HEAD(pthread); */ } else - THR_RUNQ_INSERT_TAIL(pthread); + /* THR_RUNQ_INSERT_TAIL(pthread)*/ ; } /* Unlock the threads scheduling queue: */ - THR_SCHED_UNLOCK(curthread, pthread); + THR_THREAD_UNLOCK(curthread, pthread); /* * Check for any mutex priority adjustments. This ==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_stack.c#2 (text+ko) ==== @@ -129,9 +129,8 @@ int _thr_stack_alloc(struct pthread_attr *attr) { + struct pthread *curthread = _get_curthread(); struct stack *spare_stack; - struct kse *curkse; - kse_critical_t crit; size_t stacksize; size_t guardsize; char *stackaddr; @@ -153,9 +152,7 @@ * Use the garbage collector lock for synchronization of the * spare stack lists and allocations from usrstack. */ - crit = _kse_critical_enter(); - curkse = _get_curkse(); - KSE_LOCK_ACQUIRE(curkse, &_thread_list_lock); + THR_LOCK_ACQUIRE(curthread, &_thread_list_lock); /* * If the stack and guard sizes are default, try to allocate a stack * from the default-size stack cache: @@ -185,8 +182,7 @@ } if (attr->stackaddr_attr != NULL) { /* A cached stack was found. Release the lock. */ - KSE_LOCK_RELEASE(curkse, &_thread_list_lock); - _kse_critical_leave(crit); + THR_LOCK_RELEASE(curthread, &_thread_list_lock); } else { /* Allocate a stack from usrstack. */ @@ -207,8 +203,7 @@ last_stack -= (stacksize + guardsize); /* Release the lock before mmap'ing it. */ - KSE_LOCK_RELEASE(curkse, &_thread_list_lock); - _kse_critical_leave(crit); + THR_LOCK_RELEASE(curthread, &_thread_list_lock); /* Map the stack and guard page together, and split guard page from allocated space: */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200411200451.iAK4pIO4013131>