summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authordavidxu <davidxu@FreeBSD.org>2003-08-13 01:49:07 +0000
committerdavidxu <davidxu@FreeBSD.org>2003-08-13 01:49:07 +0000
commitf9f5048801a81809cdff46eebae48dd527ffeb46 (patch)
tree74fef9905982604ae4e10707d2d1584bac2ada8c /lib
parentf245c87f99dbb36ecc02d9260723c55468e94f00 (diff)
downloadFreeBSD-src-f9f5048801a81809cdff46eebae48dd527ffeb46.zip
FreeBSD-src-f9f5048801a81809cdff46eebae48dd527ffeb46.tar.gz
Always set tcb for bound thread, and switch tcb for M:N thread at correct
time.
Diffstat (limited to 'lib')
-rw-r--r--lib/libkse/thread/thr_kern.c25
-rw-r--r--lib/libpthread/thread/thr_kern.c25
2 files changed, 36 insertions, 14 deletions
diff --git a/lib/libkse/thread/thr_kern.c b/lib/libkse/thread/thr_kern.c
index 0369b0e..c78a28a 100644
--- a/lib/libkse/thread/thr_kern.c
+++ b/lib/libkse/thread/thr_kern.c
@@ -623,7 +623,6 @@ _thr_sched_switch_unlocked(struct pthread *curthread)
/* We're in the scheduler, 5 by 5: */
curkse = _get_curkse();
- _tcb_set(curkse->k_kcb, NULL);
curthread->need_switchout = 1; /* The thread yielded on its own. */
curthread->critical_yield = 0; /* No need to yield anymore. */
@@ -672,6 +671,7 @@ _thr_sched_switch_unlocked(struct pthread *curthread)
/* Switchout the current thread. */
kse_switchout_thread(curkse, curthread);
+ _tcb_set(curkse->k_kcb, NULL);
/* Choose another thread to run. */
td = KSE_RUNQ_FIRST(curkse);
@@ -699,7 +699,8 @@ _thr_sched_switch_unlocked(struct pthread *curthread)
td->curframe = NULL;
/*
- * Continue the thread at its current frame:
+ * Continue the thread at its current frame.
+ * Note: TCB is set in _thread_switch
*/
ret = _thread_switch(curkse->k_kcb, td->tcb, 0);
/* This point should not be reached. */
@@ -782,7 +783,14 @@ kse_sched_single(struct kse_mailbox *kmbx)
* to be cleared.
*/
(void)_kse_critical_enter();
- }
+ } else {
+ /*
+ * Bound thread always has tcb set, this prevent some
+ * code from blindly setting bound thread tcb to NULL,
+ * buggy code ?
+ */
+ _tcb_set(curkse->k_kcb, curthread->tcb);
+ }
curthread->critical_yield = 0;
curthread->need_switchout = 0;
@@ -949,6 +957,12 @@ kse_sched_multi(struct kse_mailbox *kmbx)
curkse->k_flags |= KF_INITIALIZED;
}
+ /*
+ * No current thread anymore, calling _get_curthread in UTS
+ * should dump core
+ */
+ _tcb_set(curkse->k_kcb, NULL);
+
/* This may have returned from a kse_release(). */
if (KSE_WAITING(curkse)) {
DBG_MSG("Entered upcall when KSE is waiting.");
@@ -956,11 +970,8 @@ kse_sched_multi(struct kse_mailbox *kmbx)
}
/* If this is an upcall; take the scheduler lock. */
- if (curkse->k_switch == 0) {
- /* Set fake kcb */
- _tcb_set(curkse->k_kcb, NULL);
+ if (curkse->k_switch == 0)
KSE_SCHED_LOCK(curkse, curkse->k_kseg);
- }
curkse->k_switch = 0;
/*
diff --git a/lib/libpthread/thread/thr_kern.c b/lib/libpthread/thread/thr_kern.c
index 0369b0e..c78a28a 100644
--- a/lib/libpthread/thread/thr_kern.c
+++ b/lib/libpthread/thread/thr_kern.c
@@ -623,7 +623,6 @@ _thr_sched_switch_unlocked(struct pthread *curthread)
/* We're in the scheduler, 5 by 5: */
curkse = _get_curkse();
- _tcb_set(curkse->k_kcb, NULL);
curthread->need_switchout = 1; /* The thread yielded on its own. */
curthread->critical_yield = 0; /* No need to yield anymore. */
@@ -672,6 +671,7 @@ _thr_sched_switch_unlocked(struct pthread *curthread)
/* Switchout the current thread. */
kse_switchout_thread(curkse, curthread);
+ _tcb_set(curkse->k_kcb, NULL);
/* Choose another thread to run. */
td = KSE_RUNQ_FIRST(curkse);
@@ -699,7 +699,8 @@ _thr_sched_switch_unlocked(struct pthread *curthread)
td->curframe = NULL;
/*
- * Continue the thread at its current frame:
+ * Continue the thread at its current frame.
+ * Note: TCB is set in _thread_switch
*/
ret = _thread_switch(curkse->k_kcb, td->tcb, 0);
/* This point should not be reached. */
@@ -782,7 +783,14 @@ kse_sched_single(struct kse_mailbox *kmbx)
* to be cleared.
*/
(void)_kse_critical_enter();
- }
+ } else {
+ /*
+ * Bound thread always has tcb set, this prevent some
+ * code from blindly setting bound thread tcb to NULL,
+ * buggy code ?
+ */
+ _tcb_set(curkse->k_kcb, curthread->tcb);
+ }
curthread->critical_yield = 0;
curthread->need_switchout = 0;
@@ -949,6 +957,12 @@ kse_sched_multi(struct kse_mailbox *kmbx)
curkse->k_flags |= KF_INITIALIZED;
}
+ /*
+ * No current thread anymore, calling _get_curthread in UTS
+ * should dump core
+ */
+ _tcb_set(curkse->k_kcb, NULL);
+
/* This may have returned from a kse_release(). */
if (KSE_WAITING(curkse)) {
DBG_MSG("Entered upcall when KSE is waiting.");
@@ -956,11 +970,8 @@ kse_sched_multi(struct kse_mailbox *kmbx)
}
/* If this is an upcall; take the scheduler lock. */
- if (curkse->k_switch == 0) {
- /* Set fake kcb */
- _tcb_set(curkse->k_kcb, NULL);
+ if (curkse->k_switch == 0)
KSE_SCHED_LOCK(curkse, curkse->k_kseg);
- }
curkse->k_switch = 0;
/*
OpenPOWER on IntegriCloud