Deleted Added
full compact
thr_kern.c (118985) thr_kern.c (119063)
1/*
2 * Copyright (C) 2003 Daniel M. Eischen <deischen@freebsd.org>
3 * Copyright (C) 2002 Jonathon Mini <mini@freebsd.org>
4 * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 19 unchanged lines hidden (view full) ---

28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 */
35#include <sys/cdefs.h>
1/*
2 * Copyright (C) 2003 Daniel M. Eischen <deischen@freebsd.org>
3 * Copyright (C) 2002 Jonathon Mini <mini@freebsd.org>
4 * Copyright (c) 1995-1998 John Birrell <jb@cimlogic.com.au>
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 19 unchanged lines hidden (view full) ---

28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
33 *
34 */
35#include <sys/cdefs.h>
36__FBSDID("$FreeBSD: head/lib/libkse/thread/thr_kern.c 118985 2003-08-16 05:22:20Z davidxu $");
36__FBSDID("$FreeBSD: head/lib/libkse/thread/thr_kern.c 119063 2003-08-18 03:58:29Z davidxu $");
37
38#include <sys/types.h>
39#include <sys/kse.h>
40#include <sys/signalvar.h>
41#include <sys/queue.h>
42#include <machine/atomic.h>
43#include <machine/sigframe.h>
44

--- 361 unchanged lines hidden (view full) ---

406 * thread) is created.
407 */
408int
409_kse_setthreaded(int threaded)
410{
411 sigset_t sigset;
412
413 if ((threaded != 0) && (__isthreaded == 0)) {
37
38#include <sys/types.h>
39#include <sys/kse.h>
40#include <sys/signalvar.h>
41#include <sys/queue.h>
42#include <machine/atomic.h>
43#include <machine/sigframe.h>
44

--- 361 unchanged lines hidden (view full) ---

406 * thread) is created.
407 */
408int
409_kse_setthreaded(int threaded)
410{
411 sigset_t sigset;
412
413 if ((threaded != 0) && (__isthreaded == 0)) {
414 SIGFILLSET(sigset);
415 __sys_sigprocmask(SIG_SETMASK, &sigset, &_thr_initial->sigmask);
416
414 /*
415 * Tell the kernel to create a KSE for the initial thread
416 * and enable upcalls in it.
417 */
418 _kse_initial->k_flags |= KF_STARTED;
419
420#ifdef SYSTEM_SCOPE_ONLY
421 /*
422 * For bound thread, kernel reads mailbox pointer once,
423 * we'd set it here before calling kse_create
424 */
425 _tcb_set(_kse_initial->k_kcb, _thr_initial->tcb);
426 KSE_SET_MBOX(_kse_initial, _thr_initial);
427 _kse_initial->k_kcb->kcb_kmbx.km_flags |= KMF_BOUND;
417 /*
418 * Tell the kernel to create a KSE for the initial thread
419 * and enable upcalls in it.
420 */
421 _kse_initial->k_flags |= KF_STARTED;
422
423#ifdef SYSTEM_SCOPE_ONLY
424 /*
425 * For bound thread, kernel reads mailbox pointer once,
426 * we'd set it here before calling kse_create
427 */
428 _tcb_set(_kse_initial->k_kcb, _thr_initial->tcb);
429 KSE_SET_MBOX(_kse_initial, _thr_initial);
430 _kse_initial->k_kcb->kcb_kmbx.km_flags |= KMF_BOUND;
431#else
432 _thr_initial->attr.flags &= ~PTHREAD_SCOPE_SYSTEM;
433 _kse_initial->k_kseg->kg_flags &= ~KGF_SINGLE_THREAD;
434 _kse_initial->k_kcb->kcb_kmbx.km_curthread = NULL;
428#endif
435#endif
429 SIGFILLSET(sigset);
430 __sys_sigprocmask(SIG_SETMASK, &sigset, &_thr_initial->sigmask);
431 _thr_signal_init();
432
433 /*
434 * Locking functions in libc are required when there are
435 * threads other than the initial thread.
436 */
437 _thr_rtld_init();
438
439 __isthreaded = 1;

--- 518 unchanged lines hidden (view full) ---

958 }
959
960 /*
961 * No current thread anymore, calling _get_curthread in UTS
962 * should dump core
963 */
964 _tcb_set(curkse->k_kcb, NULL);
965
436
437 /*
438 * Locking functions in libc are required when there are
439 * threads other than the initial thread.
440 */
441 _thr_rtld_init();
442
443 __isthreaded = 1;

--- 518 unchanged lines hidden (view full) ---

962 }
963
964 /*
965 * No current thread anymore, calling _get_curthread in UTS
966 * should dump core
967 */
968 _tcb_set(curkse->k_kcb, NULL);
969
966 /* This may have returned from a kse_release(). */
967 if (KSE_WAITING(curkse)) {
968 DBG_MSG("Entered upcall when KSE is waiting.");
969 KSE_CLEAR_WAIT(curkse);
970 }
971
972 /* If this is an upcall; take the scheduler lock. */
973 if (curkse->k_switch == 0)
974 KSE_SCHED_LOCK(curkse, curkse->k_kseg);
975 curkse->k_switch = 0;
976
977 /*
978 * Now that the scheduler lock is held, get the current
979 * thread. The KSE's current thread cannot be safely

--- 171 unchanged lines hidden (view full) ---

1151 PANIC("Thread has returned from _thread_switch");
1152}
1153
1154static void
1155thr_resume_wrapper(int sig, siginfo_t *siginfo, ucontext_t *ucp)
1156{
1157 struct pthread *curthread = _get_curthread();
1158 struct kse *curkse;
970 /* If this is an upcall; take the scheduler lock. */
971 if (curkse->k_switch == 0)
972 KSE_SCHED_LOCK(curkse, curkse->k_kseg);
973 curkse->k_switch = 0;
974
975 /*
976 * Now that the scheduler lock is held, get the current
977 * thread. The KSE's current thread cannot be safely

--- 171 unchanged lines hidden (view full) ---

1149 PANIC("Thread has returned from _thread_switch");
1150}
1151
1152static void
1153thr_resume_wrapper(int sig, siginfo_t *siginfo, ucontext_t *ucp)
1154{
1155 struct pthread *curthread = _get_curthread();
1156 struct kse *curkse;
1159 int ret, err_save = curthread->error;
1157 int ret, err_save = errno;
1160
1161 DBG_MSG(">>> sig wrapper\n");
1162 if (curthread->lock_switch)
1163 PANIC("thr_resume_wrapper, lock_switch != 0\n");
1164 thr_resume_check(curthread, ucp, NULL);
1158
1159 DBG_MSG(">>> sig wrapper\n");
1160 if (curthread->lock_switch)
1161 PANIC("thr_resume_wrapper, lock_switch != 0\n");
1162 thr_resume_check(curthread, ucp, NULL);
1163 errno = err_save;
1165 _kse_critical_enter();
1166 curkse = _get_curkse();
1167 curthread->tcb->tcb_tmbx.tm_context = *ucp;
1164 _kse_critical_enter();
1165 curkse = _get_curkse();
1166 curthread->tcb->tcb_tmbx.tm_context = *ucp;
1168 curthread->error = err_save;
1169 ret = _thread_switch(curkse->k_kcb, curthread->tcb, 1);
1170 if (ret != 0)
1171 PANIC("thr_resume_wrapper: thread has returned "
1172 "from _thread_switch");
1173 /* THR_SETCONTEXT(ucp); */ /* not work, why ? */
1174}
1175
1176static void

--- 1108 unchanged lines hidden (view full) ---

2285 kse->k_kcb->kcb_kmbx.km_stack = kse->k_stack;
2286 kse->k_kcb->kcb_kmbx.km_udata = (void *)kse;
2287 kse->k_kcb->kcb_kmbx.km_curthread = NULL;
2288 kse->k_kcb->kcb_kmbx.km_flags = 0;
2289 kse->k_curthread = NULL;
2290 kse->k_kseg = 0;
2291 kse->k_schedq = 0;
2292 kse->k_locklevel = 0;
1167 ret = _thread_switch(curkse->k_kcb, curthread->tcb, 1);
1168 if (ret != 0)
1169 PANIC("thr_resume_wrapper: thread has returned "
1170 "from _thread_switch");
1171 /* THR_SETCONTEXT(ucp); */ /* not work, why ? */
1172}
1173
1174static void

--- 1108 unchanged lines hidden (view full) ---

2283 kse->k_kcb->kcb_kmbx.km_stack = kse->k_stack;
2284 kse->k_kcb->kcb_kmbx.km_udata = (void *)kse;
2285 kse->k_kcb->kcb_kmbx.km_curthread = NULL;
2286 kse->k_kcb->kcb_kmbx.km_flags = 0;
2287 kse->k_curthread = NULL;
2288 kse->k_kseg = 0;
2289 kse->k_schedq = 0;
2290 kse->k_locklevel = 0;
2293 SIGEMPTYSET(kse->k_sigmask);
2294 bzero(&kse->k_sigq, sizeof(kse->k_sigq));
2295 kse->k_check_sigq = 0;
2296 kse->k_flags = 0;
2291 kse->k_flags = 0;
2297 kse->k_waiting = 0;
2298 kse->k_idle = 0;
2299 kse->k_error = 0;
2300 kse->k_cpu = 0;
2301 kse->k_done = 0;
2302 kse->k_switch = 0;
2303 kse->k_sigseqno = 0;
2304}
2305

--- 183 unchanged lines hidden ---
2292 kse->k_idle = 0;
2293 kse->k_error = 0;
2294 kse->k_cpu = 0;
2295 kse->k_done = 0;
2296 kse->k_switch = 0;
2297 kse->k_sigseqno = 0;
2298}
2299

--- 183 unchanged lines hidden ---