Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 9 Apr 2005 13:30:55 GMT
From:      David Xu <davidxu@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 74795 for review
Message-ID:  <200504091330.j39DUt69044235@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=74795

Change 74795 by davidxu@davidxu_tiger on 2005/04/09 13:30:10

	1. Let parent thread report thread creating event.
	2. Breakpoint function return void.

Affected files ...

.. //depot/projects/davidxu_thread/src/lib/libthr/thread/thr_create.c#6 edit
.. //depot/projects/davidxu_thread/src/lib/libthr/thread/thr_event.c#7 edit
.. //depot/projects/davidxu_thread/src/lib/libthr/thread/thr_private.h#12 edit

Differences ...

==== //depot/projects/davidxu_thread/src/lib/libthr/thread/thr_create.c#6 (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, umtx_t *p);
+static void thread_start(struct pthread *curthread);
 
 __weak_reference(_pthread_create, pthread_create);
 
@@ -56,8 +56,7 @@
 	ucontext_t uc;
 	sigset_t sigmask, oldsigmask;
 	struct pthread *curthread, *new_thread;
-	umtx_t wait_child, *umtxp;
-	int ret = 0;
+	int ret = 0, locked;
 
 	_thr_check_init();
 
@@ -113,13 +112,7 @@
 	SIGFILLSET(uc.uc_sigmask);
 	uc.uc_stack.ss_sp = new_thread->attr.stackaddr_attr;
 	uc.uc_stack.ss_size = new_thread->attr.stacksize_attr;
-	if (!_libthr_debug)
-		umtxp = NULL;
-	else {
-		umtxp = &wait_child;
-		_thr_umtx_init(umtxp);
-	}
-	makecontext(&uc, (void (*)(void))thread_start, 2, new_thread, umtxp);
+	makecontext(&uc, (void (*)(void))thread_start, 1, new_thread);
 	/*
 	 * Check if this thread is to inherit the scheduling
 	 * attributes from its parent:
@@ -158,23 +151,31 @@
 	 * 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 (_libthr_debug) {
+		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 (umtxp != NULL) {
-		while (*umtxp == 0)
-			_thr_umtx_wait(umtxp, 0, NULL);
+	} else if (locked) {
+		_thr_report_create(curthread, new_thread);
+		THR_THREAD_UNLOCK(curthread, new_thread);
 	}
 	return (ret);
 }
@@ -215,22 +216,19 @@
 }
 
 static void
-thread_start(struct pthread *curthread, umtx_t *umtxp)
+thread_start(struct pthread *curthread)
 {
 	_tcb_set(curthread->tcb);
 
 	/* Thread was created with all signals blocked, unblock them. */
 	__sys_sigprocmask(SIG_SETMASK, &curthread->sigmask, NULL);
 
-	if (umtxp != NULL) {
-		_thr_report_create(curthread);
-		(*umtxp)++;
-		_thr_umtx_wake(umtxp, 1);
-	}
-
 	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));
 

==== //depot/projects/davidxu_thread/src/lib/libthr/thread/thr_event.c#7 (text+ko) ====

@@ -28,38 +28,41 @@
 
 #include "thr_private.h"
 
-int
+void
 _thread_create_bp(void)
 {
-	return (0);
 }
 
-int
+void
 _thread_death_bp(void)
 {
-	return (0);
 }
 
-void _thr_report_create(struct pthread *curthread)
+void
+_thr_report_create(struct pthread *curthread, struct pthread *newthread)
 {
-	_thr_report_event(curthread, TD_CREATE, NULL);
+	_thr_report_event(curthread, newthread, TD_CREATE, NULL);
 }
 
-void _thr_report_death(struct pthread *curthread)
+void
+_thr_report_death(struct pthread *curthread)
 {
-	_thr_report_event(curthread, TD_DEATH, NULL);
+	_thr_report_event(curthread, curthread, TD_DEATH, NULL);
 }
 
 void
-_thr_report_event(struct pthread *curthread, int event, void *data)
+_thr_report_event(struct pthread *curthread, struct pthread *thread,
+	int event, void *data)
 {
 	if (!_libthr_debug ||
+#if 0
 	    (curthread->enable_event == 0 && event != TD_CREATE) ||
+#endif
 	    !(_thread_event_mask & event))
 		return;
 	THR_UMTX_LOCK(curthread, &_thr_event_lock);
 	_thread_event.event = event;
-	_thread_event.thread = curthread;
+	_thread_event.thread = thread;
 	_thread_event.data = data;
 	switch (event) {
 	case TD_CREATE:

==== //depot/projects/davidxu_thread/src/lib/libthr/thread/thr_private.h#12 (text+ko) ====

@@ -736,11 +736,13 @@
 void	_thr_unlink(struct pthread *curthread, struct pthread *thread);
 void	_thr_suspend_check(struct pthread *curthread);
 void	_thr_assert_lock_level() __dead2;
-void	_thr_report_create(struct pthread *curthread);
+void	_thr_report_create(struct pthread *curthread,
+			   struct pthread *newthread);
 void	_thr_report_death(struct pthread *curthread);
-void	_thr_report_event(struct pthread *curthread, int event, void *data);
-int	_thread_create_bp(void);
-int	_thread_death_bp(void);
+void	_thr_report_event(struct pthread *curthread, struct pthread *thread,
+	int event, void *data);
+void	_thread_create_bp(void);
+void	_thread_death_bp(void);
 
 /* #include <sys/aio.h> */
 #ifdef _SYS_AIO_H_


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