PERFORCE change 57029 for review

David Xu davidxu at FreeBSD.org
Sat Jul 10 20:03:56 PDT 2004


http://perforce.freebsd.org/chv.cgi?CH=57029

Change 57029 by davidxu at davidxu_alona on 2004/07/11 03:03:32

	use macro DBG_CAN_RUN to test TMDF_DONOTRUNUSER.
	fix a searching bug in pq_first_debug().

Affected files ...

.. //depot/projects/davidxu_ksedbg/src/lib/libpthread/thread/thr_kern.c#6 edit
.. //depot/projects/davidxu_ksedbg/src/lib/libpthread/thread/thr_priority_queue.c#4 edit
.. //depot/projects/davidxu_ksedbg/src/lib/libpthread/thread/thr_private.h#6 edit

Differences ...

==== //depot/projects/davidxu_ksedbg/src/lib/libpthread/thread/thr_kern.c#6 (text+ko) ====

@@ -992,7 +992,7 @@
 	 */
 	if (curthread == NULL)
 		;  /* Nothing to do here. */
-	else if ((curthread->need_switchout == 0) &&
+	else if ((curthread->need_switchout == 0) && DBG_CAN_RUN(curthread) &&
 	    (curthread->blocked == 0) && (THR_IN_CRITICAL(curthread))) {
 		/*
 		 * Resume the thread and tell it to yield when
@@ -2542,6 +2542,6 @@
 	 * suspension event. 
 	 */
 	if ((curthread->attr.flags & PTHREAD_SCOPE_SYSTEM) == 0 &&
-	    (curthread->tcb->tcb_tmbx.tm_dflags & TMDF_DONOTRUNUSER))
+	    !DBG_CAN_RUN(curthread))
 		_thr_sched_switch(curthread);
 }

==== //depot/projects/davidxu_ksedbg/src/lib/libpthread/thread/thr_priority_queue.c#4 (text+ko) ====

@@ -250,7 +250,7 @@
 pthread_t
 _pq_first_debug(pq_queue_t *pq)
 {
-	pq_list_t *pql;
+	pq_list_t *pql, *pqlnext = NULL;
 	pthread_t pthread = NULL;
 
 	/*
@@ -259,13 +259,14 @@
 	PQ_ASSERT_INACTIVE(pq, "_pq_first: pq_active");
 	PQ_SET_ACTIVE(pq);
 
-	while (((pql = TAILQ_FIRST(&pq->pq_queue)) != NULL) &&
-	    (pthread == NULL)) {
+	for (pql = TAILQ_FIRST(&pq->pq_queue);
+	     pql != NULL && pthread == NULL; pql = pqlnext) {
 		if ((pthread = TAILQ_FIRST(&pql->pl_head)) == NULL) {
 			/*
 			 * The priority list is empty; remove the list
 			 * from the queue.
 			 */
+			pqlnext = TAILQ_NEXT(pql, pl_link);
 			TAILQ_REMOVE(&pq->pq_queue, pql, pl_link);
 
 			/* Mark the list as not being in the queue: */
@@ -276,16 +277,16 @@
 			 * test, If TMDF_DONOTRUNUSER is set after we tested it,
 			 * we will run the thread, this seems be a problem,
 			 * fortunatly, when we are being debugged, all context
-			 * switch will be done by kse_switchin, that is a syscall,
-			 * kse_switchin will check the flag again, the thread
-			 * will be returned via upcall, so next time, UTS won't
-			 * run the thread.
+			 * switch will be done by kse_switchin, that is a
+			 * syscall, kse_switchin will check the flag again,
+			 * the thread will be returned via upcall, so next
+			 * time, UTS won't run the thread.
 			 */ 
-			while (pthread != NULL && !THR_IN_CRITICAL(pthread) &&
-			       (pthread->tcb->tcb_tmbx.tm_dflags &
-			         TMDF_DONOTRUNUSER)) {
+			while (pthread != NULL && !DBG_CAN_RUN(pthread)) {
 				pthread = TAILQ_NEXT(pthread, pqe);
 			}
+			if (pthread == NULL)
+				pqlnext = TAILQ_NEXT(pql, pl_link);
 		}
 	}
 

==== //depot/projects/davidxu_ksedbg/src/lib/libpthread/thread/thr_private.h#6 (text+ko) ====

@@ -968,6 +968,8 @@
 	(((thrd)->state == PS_SUSPENDED) || \
 	(((thrd)->flags & THR_FLAGS_SUSPENDED) != 0))
 #define	THR_IS_EXITING(thrd)	(((thrd)->flags & THR_FLAGS_EXITING) != 0)
+#define DBG_CAN_RUN(thrd) (((thrd)->tcb->tcb_tmbx.tm_dflags & \
+	TMDF_DONOTRUNUSER) == 0)
 
 extern int __isthreaded;
 


More information about the p4-projects mailing list