From owner-p4-projects@FreeBSD.ORG Thu Apr 7 14:18:05 2005 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 1B85F16A4D0; Thu, 7 Apr 2005 14:18:05 +0000 (GMT) Delivered-To: perforce@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id EA7FA16A4CE for ; Thu, 7 Apr 2005 14:18:04 +0000 (GMT) Received: from repoman.freebsd.org (repoman.freebsd.org [216.136.204.115]) by mx1.FreeBSD.org (Postfix) with ESMTP id B463E43D39 for ; Thu, 7 Apr 2005 14:18:04 +0000 (GMT) (envelope-from davidxu@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.1/8.13.1) with ESMTP id j37EI4v8050082 for ; Thu, 7 Apr 2005 14:18:04 GMT (envelope-from davidxu@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.1/8.13.1/Submit) id j37EI4u5050079 for perforce@freebsd.org; Thu, 7 Apr 2005 14:18:04 GMT (envelope-from davidxu@freebsd.org) Date: Thu, 7 Apr 2005 14:18:04 GMT Message-Id: <200504071418.j37EI4u5050079@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to davidxu@freebsd.org using -f From: David Xu To: Perforce Change Reviews Subject: PERFORCE change 74664 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 07 Apr 2005 14:18:05 -0000 http://perforce.freebsd.org/chv.cgi?CH=74664 Change 74664 by davidxu@davidxu_alona on 2005/04/07 14:17:31 Wait child to report event. Affected files ... .. //depot/projects/davidxu_thread/src/lib/libthr/thread/thr_create.c#4 edit Differences ... ==== //depot/projects/davidxu_thread/src/lib/libthr/thread/thr_create.c#4 (text+ko) ==== @@ -45,7 +45,7 @@ static void free_thread(struct pthread *curthread, struct pthread *thread); static int create_stack(struct pthread_attr *pattr); static void free_stack(struct pthread *curthread, struct pthread_attr *pattr); -static void thread_start(struct pthread *curthread); +static void thread_start(struct pthread *curthread, umtx_t *p); __weak_reference(_pthread_create, pthread_create); @@ -56,6 +56,7 @@ ucontext_t uc; sigset_t sigmask, oldsigmask; struct pthread *curthread, *new_thread; + umtx_t wait_child, *umtxp; int ret = 0; _thr_check_init(); @@ -111,8 +112,13 @@ SIGFILLSET(uc.uc_sigmask); uc.uc_stack.ss_sp = new_thread->attr.stackaddr_attr; uc.uc_stack.ss_size = new_thread->attr.stacksize_attr; - makecontext(&uc, (void (*)(void))thread_start, 1, new_thread); - + if (!_libthr_debug) + umtxp = NULL; + else { + umtxp = &wait_child; + _thr_umtx_init(umtxp); + } + makecontext(&uc, (void (*)(void))thread_start, 2, new_thread, umtxp); /* * Check if this thread is to inherit the scheduling * attributes from its parent: @@ -165,6 +171,9 @@ free_thread(curthread, new_thread); (*thread) = 0; ret = EAGAIN; + } else if (umtxp != NULL) { + while (*umtxp == 0) + _thr_umtx_wait(umtxp, 0, NULL); } return (ret); } @@ -205,15 +214,18 @@ } static void -thread_start(struct pthread *curthread) +thread_start(struct pthread *curthread, umtx_t *umtxp) { _tcb_set(curthread->tcb); /* Thread was created with all signals blocked, unblock them. */ __sys_sigprocmask(SIG_SETMASK, &curthread->sigmask, NULL); - if (__predict_false(_libthr_debug)) + if (umtxp != NULL) { _thr_report_create(curthread); + (*umtxp)++; + _thr_umtx_wake(umtxp, 1); + } if (curthread->flags & THR_FLAGS_NEED_SUSPEND) _thr_suspend_check(curthread);