OLD | NEW |
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ | 1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 /* This Source Code Form is subject to the terms of the Mozilla Public | 2 /* This Source Code Form is subject to the terms of the Mozilla Public |
3 * License, v. 2.0. If a copy of the MPL was not distributed with this | 3 * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | 4 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | 5 |
6 /* | 6 /* |
7 ** File: ptthread.c | 7 ** File: ptthread.c |
8 ** Descritpion: Implemenation for threds using pthreds | 8 ** Descritpion: Implemenation for threds using pthreds |
9 ** Exports: ptthread.h | 9 ** Exports: ptthread.h |
10 */ | 10 */ |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 | 47 |
48 static struct _PT_Bookeeping | 48 static struct _PT_Bookeeping |
49 { | 49 { |
50 PRLock *ml; /* a lock to protect ourselves */ | 50 PRLock *ml; /* a lock to protect ourselves */ |
51 PRCondVar *cv; /* used to signal global things */ | 51 PRCondVar *cv; /* used to signal global things */ |
52 PRInt32 system, user; /* a count of the two different types */ | 52 PRInt32 system, user; /* a count of the two different types */ |
53 PRUintn this_many; /* number of threads allowed for exit */ | 53 PRUintn this_many; /* number of threads allowed for exit */ |
54 pthread_key_t key; /* thread private data key */ | 54 pthread_key_t key; /* thread private data key */ |
55 PRBool keyCreated; /* whether 'key' should be deleted */ | 55 PRBool keyCreated; /* whether 'key' should be deleted */ |
56 PRThread *first, *last; /* list of threads we know about */ | 56 PRThread *first, *last; /* list of threads we know about */ |
57 #if defined(_PR_DCETHREADS) || defined(_POSIX_THREAD_PRIORITY_SCHEDULING) | 57 #if defined(_PR_DCETHREADS) || _POSIX_THREAD_PRIORITY_SCHEDULING > 0 |
58 PRInt32 minPrio, maxPrio; /* range of scheduling priorities */ | 58 PRInt32 minPrio, maxPrio; /* range of scheduling priorities */ |
59 #endif | 59 #endif |
60 } pt_book = {0}; | 60 } pt_book = {0}; |
61 | 61 |
62 static void _pt_thread_death(void *arg); | 62 static void _pt_thread_death(void *arg); |
63 static void _pt_thread_death_internal(void *arg, PRBool callDestructors); | 63 static void _pt_thread_death_internal(void *arg, PRBool callDestructors); |
64 static void init_pthread_gc_support(void); | 64 static void init_pthread_gc_support(void); |
65 | 65 |
66 #if defined(_PR_DCETHREADS) || defined(_POSIX_THREAD_PRIORITY_SCHEDULING) | 66 #if defined(_PR_DCETHREADS) || _POSIX_THREAD_PRIORITY_SCHEDULING > 0 |
67 static PRIntn pt_PriorityMap(PRThreadPriority pri) | 67 static PRIntn pt_PriorityMap(PRThreadPriority pri) |
68 { | 68 { |
69 #ifdef NTO | 69 #ifdef NTO |
70 /* This priority algorithm causes lots of problems on Neutrino | 70 /* This priority algorithm causes lots of problems on Neutrino |
71 * for now I have just hard coded everything to run at priority 10 | 71 * for now I have just hard coded everything to run at priority 10 |
72 * until I can come up with a new algorithm. | 72 * until I can come up with a new algorithm. |
73 * Jerry.Kirk@Nexwarecorp.com | 73 * Jerry.Kirk@Nexwarecorp.com |
74 */ | 74 */ |
75 return 10; | 75 return 10; |
76 #else | 76 #else |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
318 if ((PRIntn)PR_PRIORITY_FIRST > (PRIntn)priority) | 318 if ((PRIntn)PR_PRIORITY_FIRST > (PRIntn)priority) |
319 priority = PR_PRIORITY_FIRST; | 319 priority = PR_PRIORITY_FIRST; |
320 else if ((PRIntn)PR_PRIORITY_LAST < (PRIntn)priority) | 320 else if ((PRIntn)PR_PRIORITY_LAST < (PRIntn)priority) |
321 priority = PR_PRIORITY_LAST; | 321 priority = PR_PRIORITY_LAST; |
322 | 322 |
323 rv = _PT_PTHREAD_ATTR_INIT(&tattr); | 323 rv = _PT_PTHREAD_ATTR_INIT(&tattr); |
324 PR_ASSERT(0 == rv); | 324 PR_ASSERT(0 == rv); |
325 | 325 |
326 if (EPERM != pt_schedpriv) | 326 if (EPERM != pt_schedpriv) |
327 { | 327 { |
328 #if !defined(_PR_DCETHREADS) && defined(_POSIX_THREAD_PRIORITY_SCHEDULING) | 328 #if !defined(_PR_DCETHREADS) && _POSIX_THREAD_PRIORITY_SCHEDULING > 0 |
329 struct sched_param schedule; | 329 struct sched_param schedule; |
330 #endif | 330 #endif |
331 | 331 |
332 #if defined(_POSIX_THREAD_PRIORITY_SCHEDULING) | 332 #if _POSIX_THREAD_PRIORITY_SCHEDULING > 0 |
333 rv = pthread_attr_setinheritsched(&tattr, PTHREAD_EXPLICIT_SCHED); | 333 rv = pthread_attr_setinheritsched(&tattr, PTHREAD_EXPLICIT_SCHED); |
334 PR_ASSERT(0 == rv); | 334 PR_ASSERT(0 == rv); |
335 #endif | 335 #endif |
336 | 336 |
337 /* Use the default scheduling policy */ | 337 /* Use the default scheduling policy */ |
338 | 338 |
339 #if defined(_PR_DCETHREADS) | 339 #if defined(_PR_DCETHREADS) |
340 rv = pthread_attr_setprio(&tattr, pt_PriorityMap(priority)); | 340 rv = pthread_attr_setprio(&tattr, pt_PriorityMap(priority)); |
341 PR_ASSERT(0 == rv); | 341 PR_ASSERT(0 == rv); |
342 #elif defined(_POSIX_THREAD_PRIORITY_SCHEDULING) | 342 #elif _POSIX_THREAD_PRIORITY_SCHEDULING > 0 |
343 rv = pthread_attr_getschedparam(&tattr, &schedule); | 343 rv = pthread_attr_getschedparam(&tattr, &schedule); |
344 PR_ASSERT(0 == rv); | 344 PR_ASSERT(0 == rv); |
345 schedule.sched_priority = pt_PriorityMap(priority); | 345 schedule.sched_priority = pt_PriorityMap(priority); |
346 rv = pthread_attr_setschedparam(&tattr, &schedule); | 346 rv = pthread_attr_setschedparam(&tattr, &schedule); |
347 PR_ASSERT(0 == rv); | 347 PR_ASSERT(0 == rv); |
348 #ifdef NTO | 348 #ifdef NTO |
349 rv = pthread_attr_setschedpolicy(&tattr, SCHED_RR); /* Round Robin */ | 349 rv = pthread_attr_setschedpolicy(&tattr, SCHED_RR); /* Round Robin */ |
350 PR_ASSERT(0 == rv); | 350 PR_ASSERT(0 == rv); |
351 #endif | 351 #endif |
352 #endif /* !defined(_PR_DCETHREADS) */ | 352 #endif /* !defined(_PR_DCETHREADS) */ |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
389 thred->arg = arg; | 389 thred->arg = arg; |
390 thred->startFunc = start; | 390 thred->startFunc = start; |
391 thred->priority = priority; | 391 thred->priority = priority; |
392 if (PR_UNJOINABLE_THREAD == state) | 392 if (PR_UNJOINABLE_THREAD == state) |
393 thred->state |= PT_THREAD_DETACHED; | 393 thred->state |= PT_THREAD_DETACHED; |
394 | 394 |
395 if (PR_LOCAL_THREAD == scope) | 395 if (PR_LOCAL_THREAD == scope) |
396 scope = PR_GLOBAL_THREAD; | 396 scope = PR_GLOBAL_THREAD; |
397 | 397 |
398 if (PR_GLOBAL_BOUND_THREAD == scope) { | 398 if (PR_GLOBAL_BOUND_THREAD == scope) { |
399 #if defined(_POSIX_THREAD_PRIORITY_SCHEDULING) | 399 #if _POSIX_THREAD_PRIORITY_SCHEDULING > 0 |
400 rv = pthread_attr_setscope(&tattr, PTHREAD_SCOPE_SYSTEM); | 400 rv = pthread_attr_setscope(&tattr, PTHREAD_SCOPE_SYSTEM); |
401 if (rv) { | 401 if (rv) { |
402 /* | 402 /* |
403 * system scope not supported | 403 * system scope not supported |
404 */ | 404 */ |
405 scope = PR_GLOBAL_THREAD; | 405 scope = PR_GLOBAL_THREAD; |
406 /* | 406 /* |
407 * reset scope | 407 * reset scope |
408 */ | 408 */ |
409 rv = pthread_attr_setscope(&tattr, PTHREAD_SCOPE_PROCESS
); | 409 rv = pthread_attr_setscope(&tattr, PTHREAD_SCOPE_PROCESS
); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
464 rv = pthread_attr_setscope(&tattr, PTHREAD_SCOPE_PROCESS
); | 464 rv = pthread_attr_setscope(&tattr, PTHREAD_SCOPE_PROCESS
); |
465 PR_ASSERT(0 == rv); | 465 PR_ASSERT(0 == rv); |
466 thred->state &= ~PT_THREAD_BOUND; | 466 thred->state &= ~PT_THREAD_BOUND; |
467 } | 467 } |
468 #else | 468 #else |
469 /* Remember that we don't have thread scheduling privilege. */ | 469 /* Remember that we don't have thread scheduling privilege. */ |
470 pt_schedpriv = EPERM; | 470 pt_schedpriv = EPERM; |
471 PR_LOG(_pr_thread_lm, PR_LOG_MIN, | 471 PR_LOG(_pr_thread_lm, PR_LOG_MIN, |
472 ("_PR_CreateThread: no thread scheduling privilege")); | 472 ("_PR_CreateThread: no thread scheduling privilege")); |
473 /* Try creating the thread again without setting priority. */ | 473 /* Try creating the thread again without setting priority. */ |
474 #if defined(_POSIX_THREAD_PRIORITY_SCHEDULING) | 474 #if _POSIX_THREAD_PRIORITY_SCHEDULING > 0 |
475 rv = pthread_attr_setinheritsched(&tattr, PTHREAD_INHERIT_SCHED); | 475 rv = pthread_attr_setinheritsched(&tattr, PTHREAD_INHERIT_SCHED); |
476 PR_ASSERT(0 == rv); | 476 PR_ASSERT(0 == rv); |
477 #endif | 477 #endif |
478 #endif /* IRIX */ | 478 #endif /* IRIX */ |
479 rv = _PT_PTHREAD_CREATE(&id, tattr, _pt_root, thred); | 479 rv = _PT_PTHREAD_CREATE(&id, tattr, _pt_root, thred); |
480 } | 480 } |
481 #endif | 481 #endif |
482 | 482 |
483 if (0 != rv) | 483 if (0 != rv) |
484 { | 484 { |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
685 PR_ASSERT(NULL != thred); | 685 PR_ASSERT(NULL != thred); |
686 | 686 |
687 if ((PRIntn)PR_PRIORITY_FIRST > (PRIntn)newPri) | 687 if ((PRIntn)PR_PRIORITY_FIRST > (PRIntn)newPri) |
688 newPri = PR_PRIORITY_FIRST; | 688 newPri = PR_PRIORITY_FIRST; |
689 else if ((PRIntn)PR_PRIORITY_LAST < (PRIntn)newPri) | 689 else if ((PRIntn)PR_PRIORITY_LAST < (PRIntn)newPri) |
690 newPri = PR_PRIORITY_LAST; | 690 newPri = PR_PRIORITY_LAST; |
691 | 691 |
692 #if defined(_PR_DCETHREADS) | 692 #if defined(_PR_DCETHREADS) |
693 rv = pthread_setprio(thred->id, pt_PriorityMap(newPri)); | 693 rv = pthread_setprio(thred->id, pt_PriorityMap(newPri)); |
694 /* pthread_setprio returns the old priority */ | 694 /* pthread_setprio returns the old priority */ |
695 #elif defined(_POSIX_THREAD_PRIORITY_SCHEDULING) | 695 #elif _POSIX_THREAD_PRIORITY_SCHEDULING > 0 |
696 if (EPERM != pt_schedpriv) | 696 if (EPERM != pt_schedpriv) |
697 { | 697 { |
698 int policy; | 698 int policy; |
699 struct sched_param schedule; | 699 struct sched_param schedule; |
700 | 700 |
701 rv = pthread_getschedparam(thred->id, &policy, &schedule); | 701 rv = pthread_getschedparam(thred->id, &policy, &schedule); |
702 if(0 == rv) { | 702 if(0 == rv) { |
703 schedule.sched_priority = pt_PriorityMap(newPri); | 703 schedule.sched_priority = pt_PriorityMap(newPri); |
704 rv = pthread_setschedparam(thred->id, policy, &schedule)
; | 704 rv = pthread_setschedparam(thred->id, policy, &schedule)
; |
705 if (EPERM == rv) | 705 if (EPERM == rv) |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
914 /* | 914 /* |
915 * On BSD/OS (3.1 and 4.0), the pthread subsystem is lazily | 915 * On BSD/OS (3.1 and 4.0), the pthread subsystem is lazily |
916 * initialized, but pthread_self() fails to initialize | 916 * initialized, but pthread_self() fails to initialize |
917 * pthreads and hence returns a null thread ID if invoked | 917 * pthreads and hence returns a null thread ID if invoked |
918 * by the primordial thread before any other pthread call. | 918 * by the primordial thread before any other pthread call. |
919 * So we explicitly initialize pthreads here. | 919 * So we explicitly initialize pthreads here. |
920 */ | 920 */ |
921 pthread_init(); | 921 pthread_init(); |
922 #endif | 922 #endif |
923 | 923 |
924 #if defined(_PR_DCETHREADS) || defined(_POSIX_THREAD_PRIORITY_SCHEDULING) | 924 #if defined(_PR_DCETHREADS) || _POSIX_THREAD_PRIORITY_SCHEDULING > 0 |
925 #if defined(FREEBSD) | 925 #if defined(FREEBSD) |
926 { | 926 { |
927 pthread_attr_t attr; | 927 pthread_attr_t attr; |
928 int policy; | 928 int policy; |
929 /* get the min and max priorities of the default policy */ | 929 /* get the min and max priorities of the default policy */ |
930 pthread_attr_init(&attr); | 930 pthread_attr_init(&attr); |
931 pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); | 931 pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED); |
932 pthread_attr_getschedpolicy(&attr, &policy); | 932 pthread_attr_getschedpolicy(&attr, &policy); |
933 pt_book.minPrio = sched_get_priority_min(policy); | 933 pt_book.minPrio = sched_get_priority_min(policy); |
934 PR_ASSERT(-1 != pt_book.minPrio); | 934 PR_ASSERT(-1 != pt_book.minPrio); |
(...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1805 PR_IMPLEMENT(const char *) PR_GetThreadName(const PRThread *thread) | 1805 PR_IMPLEMENT(const char *) PR_GetThreadName(const PRThread *thread) |
1806 { | 1806 { |
1807 if (!thread) | 1807 if (!thread) |
1808 return NULL; | 1808 return NULL; |
1809 return thread->name; | 1809 return thread->name; |
1810 } | 1810 } |
1811 | 1811 |
1812 #endif /* defined(_PR_PTHREADS) || defined(_PR_DCETHREADS) */ | 1812 #endif /* defined(_PR_PTHREADS) || defined(_PR_DCETHREADS) */ |
1813 | 1813 |
1814 /* ptthread.c */ | 1814 /* ptthread.c */ |
OLD | NEW |