Merged with HEAD from 8/18 or so. unlabeled-3.19.12
authorcls%seawood.org
Fri, 20 Aug 1999 16:21:49 +0000
branchunlabeled-3.19.12
changeset 783 38fb81d8f88d4a242240f363d2030079b8653c51
parent 740 7f5799584bd24f35e449f6c9098585aa4455e05b
child 823 572e0d988c7296ffb8590d83a5d01519c99fe375
push idunknown
push userunknown
push dateunknown
Merged with HEAD from 8/18 or so.
pr/src/pthreads/ptthread.c
--- a/pr/src/pthreads/ptthread.c
+++ b/pr/src/pthreads/ptthread.c
@@ -57,18 +57,27 @@ static struct _PT_Bookeeping
 } pt_book = {0};
 
 static void _pt_thread_death(void *arg);
 static void init_pthread_gc_support(void);
 
 #if defined(_PR_DCETHREADS) || defined(_POSIX_THREAD_PRIORITY_SCHEDULING)
 static PRIntn pt_PriorityMap(PRThreadPriority pri)
 {
+#ifdef NTO
+    /* This priority algorithm causes lots of problems on Neutrino
+     * for now I have just hard coded everything to run at priority 10
+     * until I can come up with a new algorithm.
+     *     Jerry.Kirk@Nexwarecorp.com
+     */
+    return 10;
+#else
     return pt_book.minPrio +
 	    pri * (pt_book.maxPrio - pt_book.minPrio) / PR_PRIORITY_LAST;
+#endif
 }
 #endif
 
 /*
 ** Initialize a stack for a native pthread thread
 */
 static void _PR_InitializeStack(PRThreadStack *ts)
 {
@@ -241,17 +250,17 @@ static PRThread* _PR_CreateThread(
 
     if (!_pr_initialized) _PR_ImplicitInitialization();
 
     if ((PRIntn)PR_PRIORITY_FIRST > (PRIntn)priority)
         priority = PR_PRIORITY_FIRST;
     else if ((PRIntn)PR_PRIORITY_LAST < (PRIntn)priority)
         priority = PR_PRIORITY_LAST;
 
-    rv = PTHREAD_ATTR_INIT(&tattr);
+    rv = _PT_PTHREAD_ATTR_INIT(&tattr);
     PR_ASSERT(0 == rv);
 
     if (EPERM != pt_schedpriv)
     {
 #if !defined(_PR_DCETHREADS) && defined(_POSIX_THREAD_PRIORITY_SCHEDULING)
         struct sched_param schedule;
 #endif
 
@@ -266,16 +275,20 @@ static PRThread* _PR_CreateThread(
         rv = pthread_attr_setprio(&tattr, pt_PriorityMap(priority));
         PR_ASSERT(0 == rv);
 #elif defined(_POSIX_THREAD_PRIORITY_SCHEDULING)
         rv = pthread_attr_getschedparam(&tattr, &schedule);
         PR_ASSERT(0 == rv);
         schedule.sched_priority = pt_PriorityMap(priority);
         rv = pthread_attr_setschedparam(&tattr, &schedule);
         PR_ASSERT(0 == rv);
+#ifdef NTO
+        rv = pthread_attr_setschedpolicy(&tattr, SCHED_RR); /* Round Robin */
+        PR_ASSERT(0 == rv);
+#endif
 #endif /* !defined(_PR_DCETHREADS) */
     }
 
     /*
      * DCE threads can't set detach state before creating the thread.
      * AIX can't set detach late. Why can't we all just get along?
      */
 #if !defined(_PR_DCETHREADS)
@@ -363,17 +376,17 @@ static PRThread* _PR_CreateThread(
         else pt_book.user += 1;
         PR_Unlock(pt_book.ml);
 
         /*
          * We pass a pointer to a local copy (instead of thred->id)
          * to pthread_create() because who knows what wacky things
          * pthread_create() may be doing to its argument.
          */
-        rv = PTHREAD_CREATE(&id, tattr, _pt_root, thred);
+        rv = _PT_PTHREAD_CREATE(&id, tattr, _pt_root, thred);
 
 #if !defined(_PR_DCETHREADS)
         if (EPERM == rv)
         {
 #if defined(IRIX)
         	if (PR_GLOBAL_BOUND_THREAD == scope) {
 				/*
 				 * SCOPE_SYSTEM requires appropriate privilege
@@ -389,17 +402,17 @@ static PRThread* _PR_CreateThread(
             PR_LOG(_pr_thread_lm, PR_LOG_MIN,
                 ("_PR_CreateThread: no thread scheduling privilege"));
             /* Try creating the thread again without setting priority. */
 #if defined(_POSIX_THREAD_PRIORITY_SCHEDULING)
             rv = pthread_attr_setinheritsched(&tattr, PTHREAD_INHERIT_SCHED);
             PR_ASSERT(0 == rv);
 #endif
 #endif	/* IRIX */
-            rv = PTHREAD_CREATE(&id, tattr, _pt_root, thred);
+            rv = _PT_PTHREAD_CREATE(&id, tattr, _pt_root, thred);
         }
 #endif
 
         if (0 != rv)
         {
 #if defined(_PR_DCETHREADS)
             PRIntn oserr = errno;
 #else
@@ -435,17 +448,17 @@ static PRThread* _PR_CreateThread(
             PR_Lock(pt_book.ml);
             thred->okToDelete = PR_TRUE;
             PR_NotifyAllCondVar(pt_book.cv);
             PR_Unlock(pt_book.ml);
         }
     }
 
 done:
-    rv = PTHREAD_ATTR_DESTROY(&tattr);
+    rv = _PT_PTHREAD_ATTR_DESTROY(&tattr);
     PR_ASSERT(0 == rv);
 
     return thred;
 }  /* _PR_CreateThread */
 
 PR_IMPLEMENT(PRThread*) PR_CreateThread(
     PRThreadType type, void (*start)(void *arg), void *arg,
     PRThreadPriority priority, PRThreadScope scope,
@@ -541,17 +554,17 @@ PR_IMPLEMENT(PRStatus) PR_JoinThread(PRT
 PR_IMPLEMENT(void) PR_DetachThread() { }  /* PR_DetachThread */
 
 PR_IMPLEMENT(PRThread*) PR_GetCurrentThread()
 {
     void *thred;
 
     if (!_pr_initialized) _PR_ImplicitInitialization();
 
-    PTHREAD_GETSPECIFIC(pt_book.key, thred);
+    _PT_PTHREAD_GETSPECIFIC(pt_book.key, thred);
     if (NULL == thred) thred = pt_AttachThread();
     PR_ASSERT(NULL != thred);
     return (PRThread*)thred;
 }  /* PR_GetCurrentThread */
 
 PR_IMPLEMENT(PRThreadScope) PR_GetThreadScope(const PRThread *thred)
 {
     return (thred->state & PT_THREAD_BOUND) ?
@@ -616,17 +629,17 @@ PR_IMPLEMENT(void) PR_SetThreadPriority(
 #if 0
 PR_IMPLEMENT(PRStatus) PR_NewThreadPrivateIndex(
     PRUintn *newIndex, PRThreadPrivateDTOR destructor)
 {
     int rv;
 
     if (!_pr_initialized) _PR_ImplicitInitialization();
 
-    rv = PTHREAD_KEY_CREATE((pthread_key_t*)newIndex, destructor);
+    rv = _PT_PTHREAD_KEY_CREATE((pthread_key_t*)newIndex, destructor);
 
     if (0 == rv)
     {
         PR_Lock(pt_book.ml);
         if (*newIndex >= pt_book.highwater)
             pt_book.highwater = *newIndex + 1;
         PR_Unlock(pt_book.ml);
         return PR_SUCCESS;
@@ -650,17 +663,17 @@ PR_IMPLEMENT(PRStatus) PR_SetThreadPriva
     PR_SetError(PR_UNKNOWN_ERROR, rv);
     return PR_FAILURE;
 }  /* PR_SetThreadPrivate */
 
 PR_IMPLEMENT(void*) PR_GetThreadPrivate(PRUintn index)
 {
     void *result = NULL;
     if ((pthread_key_t)index < pt_book.highwater)
-        PTHREAD_GETSPECIFIC((pthread_key_t)index, result);
+        _PT_PTHREAD_GETSPECIFIC((pthread_key_t)index, result);
     return result;
 }  /* PR_GetThreadPrivate */
 #endif
 
 PR_IMPLEMENT(PRStatus) PR_Interrupt(PRThread *thred)
 {
     /*
     ** If the target thread indicates that it's waiting,
@@ -713,17 +726,17 @@ PR_IMPLEMENT(PRStatus) PR_Yield()
 PR_IMPLEMENT(PRStatus) PR_Sleep(PRIntervalTime ticks)
 {
     PRStatus rv;
 
     if (!_pr_initialized) _PR_ImplicitInitialization();
 
     if (PR_INTERVAL_NO_WAIT == ticks)
     {
-        PTHREAD_YIELD();
+        _PT_PTHREAD_YIELD();
         rv = PR_SUCCESS;
     }
     else
     {
         PRCondVar *cv;
         PRIntervalTime timein;
 
         timein = PR_IntervalNow();
@@ -836,17 +849,17 @@ void _PR_InitThreads(
      * NB: The destructor logic seems to have a bug so it isn't used.
      * NBB: Oh really? I'm going to give it a spin - AOF 19 June 1998.
      * More info - the problem is that pthreads calls the destructor
      * eagerly as the thread returns from its root, rather than lazily
      * after the thread is joined. Therefore, threads that are joining
      * and holding PRThread references are actually holding pointers to
      * nothing.
      */
-    rv = PTHREAD_KEY_CREATE(&pt_book.key, _pt_thread_death);
+    rv = _PT_PTHREAD_KEY_CREATE(&pt_book.key, _pt_thread_death);
     PR_ASSERT(0 == rv);
     rv = pthread_setspecific(pt_book.key, thred);
     PR_ASSERT(0 == rv);    
     PR_SetThreadPriority(thred, priority);
 }  /* _PR_InitThreads */
 
 PR_IMPLEMENT(PRStatus) PR_Cleanup()
 {
@@ -1195,18 +1208,16 @@ static void PR_SuspendSet(PRThread *thre
 #else
     rv = pthread_kill (thred->id, SIGUSR2);
 #endif
     PR_ASSERT(0 == rv);
 }
 
 static void PR_SuspendTest(PRThread *thred)
 {
-    PRIntn rv;
-
     PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS, 
 	   ("Begin PR_SuspendTest thred %X thread id = %X\n", thred, thred->id));
 
 
     /*
      * Wait for the thread to be really suspended. This happens when the
      * suspend signal handler stores the stack pointer and sets the state
      * to suspended. 
@@ -1218,17 +1229,17 @@ static void PR_SuspendTest(PRThread *thr
     {
 	    pthread_cond_timedwait(
 	        &thred->suspendResumeCV, &thred->suspendResumeMutex, &onemillisec);
 	}
 	pthread_mutex_unlock(&thred->suspendResumeMutex);
 #else
     while ((thred->suspend & PT_THREAD_SUSPENDED) == 0)
     {
-		rv = sigtimedwait(&sigwait_set, NULL, &onemillisec);
+		PRIntn rv = sigtimedwait(&sigwait_set, NULL, &onemillisec);
     	PR_ASSERT(-1 == rv);
 	}
 #endif
 
     PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS,
         ("End PR_SuspendTest thred %X tid %X\n", thred, thred->id));
 }  /* PR_SuspendTest */