Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 7 Apr 2005 14:18:04 GMT
From:      David Xu <davidxu@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 74664 for review
Message-ID:  <200504071418.j37EI4u5050079@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200504071418.j37EI4u5050079>