Date: Thu, 7 Apr 2005 22:37:12 GMT From: David Xu <davidxu@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 74695 for review Message-ID: <200504072237.j37MbCas086861@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=74695 Change 74695 by davidxu@davidxu_alona on 2005/04/07 22:37:08 Reuse tid as a state indicating if the thread is exited by kernel, thr_exit will write a value into user given address, but there is a mistake that it writes out 1. :( fortunately, thread id 1 is never assigned to user thread, so we are safe to test if a thread is dead by comparing it with 1. Affected files ... .. //depot/projects/davidxu_thread/src/lib/libthr/pthread.map#6 edit .. //depot/projects/davidxu_thread/src/lib/libthr/thread/thr_create.c#5 edit .. //depot/projects/davidxu_thread/src/lib/libthr/thread/thr_exit.c#4 edit .. //depot/projects/davidxu_thread/src/lib/libthr/thread/thr_private.h#11 edit .. //depot/projects/davidxu_thread/src/lib/libthr/thread/thr_symbols.c#4 edit .. //depot/projects/davidxu_thread/src/lib/libthread_db/libthr_db.c#7 edit Differences ... ==== //depot/projects/davidxu_thread/src/lib/libthr/pthread.map#6 (text+ko) ==== @@ -358,7 +358,6 @@ _thread_off_state; _thread_off_thr_locklevel; _thread_off_tlsindex; - _thread_off_isdead; _thread_off_enable_event; _thread_size_key; _thread_state_running; ==== //depot/projects/davidxu_thread/src/lib/libthr/thread/thr_create.c#5 (text+ko) ==== @@ -93,9 +93,10 @@ 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); } @@ -182,7 +183,7 @@ free_thread(struct pthread *curthread, struct pthread *thread) { free_stack(curthread, &thread->attr); - curthread->terminated = 1; + curthread->tid = TID_TERMINATED; _thr_free(curthread, thread); } ==== //depot/projects/davidxu_thread/src/lib/libthr/thread/thr_exit.c#4 (text+ko) ==== @@ -132,7 +132,7 @@ _thr_umtx_wake(&curthread->state, INT_MAX); if (__predict_false(_libthr_debug)) _thr_report_death(curthread); - thr_exit(&curthread->terminated); + thr_exit(&curthread->tid); PANIC("thr_exit() returned"); /* Never reach! */ } ==== //depot/projects/davidxu_thread/src/lib/libthr/thread/thr_private.h#11 (text+ko) ==== @@ -345,11 +345,9 @@ */ umtx_t lock; - /* Thread is terminated in kernel, written by kernel. */ - long terminated; - /* Kernel thread id. */ long tid; +#define TID_TERMINATED 1 /* Internal condition variable cycle number. */ umtx_t cycle; ==== //depot/projects/davidxu_thread/src/lib/libthr/thread/thr_symbols.c#4 (text+ko) ==== @@ -48,7 +48,6 @@ int _thread_off_thr_locklevel = offsetof(struct pthread, locklevel); int _thread_off_linkmap = offsetof(Obj_Entry, linkmap); int _thread_off_tlsindex = offsetof(Obj_Entry, tlsindex); -int _thread_off_isdead = offsetof(struct pthread, terminated); int _thread_off_enable_event = offsetof(struct pthread, enable_event); int _thread_size_key = sizeof(struct pthread_key); int _thread_off_key_allocated = offsetof(struct pthread_key, allocated); ==== //depot/projects/davidxu_thread/src/lib/libthread_db/libthr_db.c#7 (text+ko) ==== @@ -66,7 +66,6 @@ int thread_off_thr_locklevel; int thread_off_next; int thread_off_state; - int thread_off_isdead; int thread_off_tid; int thread_max_keys; int thread_off_key_allocated; @@ -214,7 +213,6 @@ LOOKUP_VAL(ph, "_thread_off_thr_locklevel", &ta->thread_off_thr_locklevel); LOOKUP_VAL(ph, "_thread_off_next", &ta->thread_off_next); LOOKUP_VAL(ph, "_thread_off_state", &ta->thread_off_state); - LOOKUP_VAL(ph, "_thread_off_isdead", &ta->thread_off_isdead); LOOKUP_VAL(ph, "_thread_max_keys", &ta->thread_max_keys); LOOKUP_VAL(ph, "_thread_off_key_allocated", &ta->thread_off_key_allocated); LOOKUP_VAL(ph, "_thread_off_key_destructor", &ta->thread_off_key_destructor); @@ -260,7 +258,8 @@ prgregset_t gregs; TAILQ_HEAD(, pthread) thread_list; psaddr_t pt; - int ret, isdead; + int ret; + long lwp; TDBG_FUNC(); @@ -295,11 +294,11 @@ return (TD_NOTHR); } ret = ps_pread(ta->ph, - pt + ta->thread_off_isdead, - &isdead, sizeof(isdead)); + pt + ta->thread_off_tid, + &lwp, sizeof(long)); if (ret != 0) return (P2T(ret)); - if (isdead) { + if (lwp == 1) { ta->map[id].used = 0; return (TD_NOTHR); } @@ -372,24 +371,18 @@ pt = (psaddr_t)thread_list.tqh_first; while (pt != 0) { - ret = ps_pread(ta->ph, pt + ta->thread_off_isdead, &isdead, - sizeof(isdead)); + ret = ps_pread(ta->ph, pt + ta->thread_off_tid, &tmp_lwp, + sizeof(tmp_lwp)); if (ret != 0) return (P2T(ret)); - if (!isdead) { - ret = ps_pread(ta->ph, pt + ta->thread_off_tid, &tmp_lwp, - sizeof(tmp_lwp)); - if (ret != 0) - return (P2T(ret)); - if (tmp_lwp != 0) { - th.th_ta = ta; - th.th_tid = pt_map_thread(ta, tmp_lwp, pt); - th.th_thread = pt; - if (th.th_tid == -1) - return (TD_MALLOC); - if ((*callback)(&th, cbdata_p)) - return (TD_DBERR); - } + if (tmp_lwp != 0 && tmp_lwp != 1) { + th.th_ta = ta; + th.th_tid = pt_map_thread(ta, tmp_lwp, pt); + th.th_thread = pt; + if (th.th_tid == -1) + return (TD_MALLOC); + if ((*callback)(&th, cbdata_p)) + return (TD_DBERR); } /* get next thread */ ret = ps_pread(ta->ph, pt + ta->thread_off_next, &pt,
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200504072237.j37MbCas086861>