diff options
author | davidxu <davidxu@FreeBSD.org> | 2005-04-12 03:00:28 +0000 |
---|---|---|
committer | davidxu <davidxu@FreeBSD.org> | 2005-04-12 03:00:28 +0000 |
commit | 2cf5eeb00151f72e5aa07f0289c2889752eb07d9 (patch) | |
tree | b5ca39973148c65442650488e554719cd7db2deb /lib/libthr/thread/thr_create.c | |
parent | c874648f8b61fce9d0fd977d6502638d882c2f33 (diff) | |
download | FreeBSD-src-2cf5eeb00151f72e5aa07f0289c2889752eb07d9.zip FreeBSD-src-2cf5eeb00151f72e5aa07f0289c2889752eb07d9.tar.gz |
Add debugger event reporting support, current only TD_CREATE and TD_DEATH
events are reported.
Diffstat (limited to 'lib/libthr/thread/thr_create.c')
-rw-r--r-- | lib/libthr/thread/thr_create.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/lib/libthr/thread/thr_create.c b/lib/libthr/thread/thr_create.c index d5e9a62..af0697c 100644 --- a/lib/libthr/thread/thr_create.c +++ b/lib/libthr/thread/thr_create.c @@ -56,7 +56,7 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr, ucontext_t uc; sigset_t sigmask, oldsigmask; struct pthread *curthread, *new_thread; - int ret = 0; + int ret = 0, locked; _thr_check_init(); @@ -92,9 +92,10 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr, else if (_thr_scope_system < 0) new_thread->attr.flags &= ~PTHREAD_SCOPE_SYSTEM; + new_thread->tid = TID_TERMINATED; + if (create_stack(&new_thread->attr) != 0) { /* Insufficient memory to create a stack: */ - new_thread->terminated = 1; _thr_free(curthread, new_thread); return (EAGAIN); } @@ -151,20 +152,31 @@ _pthread_create(pthread_t * thread, const pthread_attr_t * attr, * it can not handle signal, so we should masks all signals here. */ SIGFILLSET(sigmask); + SIGDELSET(sigmask, SIGTRAP); __sys_sigprocmask(SIG_SETMASK, &sigmask, &oldsigmask); new_thread->sigmask = oldsigmask; /* Add the new thread. */ _thr_link(curthread, new_thread); /* Return thread pointer eariler so that new thread can use it. */ (*thread) = new_thread; + if (SHOULD_REPORT_EVENT(curthread, TD_CREATE)) { + THR_THREAD_LOCK(curthread, new_thread); + locked = 1; + } else + locked = 0; /* Schedule the new thread. */ ret = thr_create(&uc, &new_thread->tid, 0); __sys_sigprocmask(SIG_SETMASK, &oldsigmask, NULL); if (ret != 0) { + if (locked) + THR_THREAD_UNLOCK(curthread, new_thread); _thr_unlink(curthread, new_thread); free_thread(curthread, new_thread); (*thread) = 0; ret = EAGAIN; + } else if (locked) { + _thr_report_creation(curthread, new_thread); + THR_THREAD_UNLOCK(curthread, new_thread); } return (ret); } @@ -173,7 +185,7 @@ static void free_thread(struct pthread *curthread, struct pthread *thread) { free_stack(curthread, &thread->attr); - curthread->terminated = 1; + curthread->tid = TID_TERMINATED; _thr_free(curthread, thread); } @@ -215,6 +227,9 @@ thread_start(struct pthread *curthread) if (curthread->flags & THR_FLAGS_NEED_SUSPEND) _thr_suspend_check(curthread); + THR_LOCK(curthread); + THR_UNLOCK(curthread); + /* Run the current thread's start routine with argument: */ pthread_exit(curthread->start_routine(curthread->arg)); |