PERFORCE change 67979 for review
David Xu
davidxu at FreeBSD.org
Fri Dec 31 06:57:08 PST 2004
http://perforce.freebsd.org/chv.cgi?CH=67979
Change 67979 by davidxu at davidxu_tiger on 2004/12/31 14:56:42
rework join related code.
Affected files ...
.. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_detach.c#3 edit
Differences ...
==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_detach.c#3 (text+ko) ====
@@ -44,58 +44,46 @@
{
struct pthread *curthread = _get_curthread();
struct pthread *joiner;
- long tid = -1;
- int rval = 0;
+ int rval;
- /* Check for invalid calling parameters: */
- if (pthread == NULL || pthread->magic != THR_MAGIC)
- /* Return an invalid argument error: */
- rval = EINVAL;
+ if (pthread == NULL)
+ return (EINVAL);
- else if ((rval = _thr_ref_add(curthread, pthread,
- /*include dead*/1)) != 0) {
- /* Return an error: */
+ THREAD_LIST_LOCK(curthread);
+ if ((rval = _thr_find_thread(curthread, pthread,
+ /*include dead*/1)) != 0) {
+ THREAD_LIST_UNLOCK(curthread);
+ return (rval);
}
- /* Check if the thread is already detached: */
- else if ((pthread->attr.flags & PTHREAD_DETACHED) != 0) {
- /* Return an error: */
- _thr_ref_delete(curthread, pthread);
- rval = EINVAL;
- } else {
- /* Lock the detached thread: */
- THR_THREAD_LOCK(curthread, pthread);
+ /* Check if the thread is already detached. */
+ if ((pthread->tlflags & TLFLAGS_DETACHED) != 0) {
+ THREAD_LIST_UNLOCK(curthread);
+ return (EINVAL);
+ }
- /* Flag the thread as detached: */
- pthread->attr.flags |= PTHREAD_DETACHED;
+ /* Flag the thread as detached. */
+ pthread->tlflags |= TLFLAGS_DETACHED;
- /* Retrieve any joining thread and remove it: */
- joiner = pthread->joiner;
- THR_THREAD_UNLOCK(curthread, pthread);
+ /* Retrieve any joining thread and remove it. */
+ joiner = pthread->joiner;
- /* 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_THREAD_LOCK(curthread, joiner);
- 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;
-
- tid = _thr_setrunnable_unlocked(joiner);
- }
- THR_THREAD_UNLOCK(curthread, joiner);
- _thr_ref_delete(curthread, joiner);
+ /* See if there is a thread waiting in pthread_join(). */
+ if (joiner != NULL) {
+ THR_THREAD_LOCK(curthread, joiner);
+ 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;
+ joiner->cycle++;
+ umtx_wake((struct umtx *)&joiner->cycle, 1);
}
- _thr_ref_delete(curthread, pthread);
- if (tid != -1)
- thr_wake(tid);
+ THR_THREAD_UNLOCK(curthread, joiner);
}
+ THREAD_LIST_UNLOCK(curthread);
- /* Return the completion status: */
- return (rval);
+ return (0);
}
More information about the p4-projects
mailing list