PERFORCE change 67986 for review
David Xu
davidxu at FreeBSD.org
Fri Dec 31 07:06:23 PST 2004
http://perforce.freebsd.org/chv.cgi?CH=67986
Change 67986 by davidxu at davidxu_tiger on 2004/12/31 15:05:22
now suspending a thread works, required by java.
Affected files ...
.. //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_resume_np.c#3 edit
Differences ...
==== //depot/projects/davidxu_thread/src/lib/libthread/thread/thr_resume_np.c#3 (text+ko) ====
@@ -35,29 +35,25 @@
#include <pthread.h>
#include "thr_private.h"
-static long resume_common(struct pthread *);
-
__weak_reference(_pthread_resume_np, pthread_resume_np);
__weak_reference(_pthread_resume_all_np, pthread_resume_all_np);
+static void inline resume_common(struct pthread *thread);
/* Resume a thread: */
int
_pthread_resume_np(pthread_t thread)
{
struct pthread *curthread = _get_curthread();
- long tid = -1;
int ret;
/* Add a reference to the thread: */
if ((ret = _thr_ref_add(curthread, thread, /*include dead*/0)) == 0) {
/* Lock the threads scheduling queue: */
THR_THREAD_LOCK(curthread, thread);
- tid = resume_common(thread);
+ resume_common(thread);
THR_THREAD_UNLOCK(curthread, thread);
_thr_ref_delete(curthread, thread);
- if (tid !=-1)
- thr_wake(tid);
}
return (ret);
}
@@ -67,38 +63,28 @@
{
struct pthread *curthread = _get_curthread();
struct pthread *thread;
- long tid;
/* Take the thread list lock: */
- THR_LOCK_ACQUIRE(curthread, &_thread_list_lock);
+ THREAD_LIST_LOCK(curthread);
TAILQ_FOREACH(thread, &_thread_list, tle) {
if (thread != curthread) {
THR_THREAD_LOCK(curthread, thread);
- tid = resume_common(thread);
+ resume_common(thread);
THR_THREAD_UNLOCK(curthread, thread);
- if (tid != -1)
- thr_wake(tid);
}
}
/* Release the thread list lock: */
- THR_LOCK_RELEASE(curthread, &_thread_list_lock);
+ THREAD_LIST_UNLOCK(curthread);
}
-static long
+static void inline
resume_common(struct pthread *thread)
{
/* Clear the suspend flag: */
- thread->flags &= ~THR_FLAGS_SUSPENDED;
-
- /*
- * If the thread's state is suspended, that means it is
- * now runnable but not in any scheduling queue. Set the
- * state to running and insert it into the run queue.
- */
- if (thread->state == PS_SUSPENDED)
- return (_thr_setrunnable_unlocked(thread));
- else
- return (-1);
+ thread->flags &= ~THR_FLAGS_NEED_SUSPEND;
+ thread->cycle++;
+ umtx_wake((struct umtx *)&thread->cycle, 1);
+ thr_kill(thread->tid, SIGCANCEL);
}
More information about the p4-projects
mailing list