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 */ |
11 | 11 |
12 #if defined(_PR_PTHREADS) || defined(_PR_DCETHREADS) | 12 #if defined(_PR_PTHREADS) || defined(_PR_DCETHREADS) |
13 | 13 |
14 #include "prlog.h" | 14 #include "prlog.h" |
15 #include "primpl.h" | 15 #include "primpl.h" |
16 #include "prpdce.h" | 16 #include "prpdce.h" |
17 | 17 |
18 #include <pthread.h> | 18 #include <pthread.h> |
19 #include <unistd.h> | 19 #include <unistd.h> |
20 #include <string.h> | 20 #include <string.h> |
21 #include <signal.h> | 21 #include <signal.h> |
22 #include <dlfcn.h> | 22 #include <dlfcn.h> |
23 | 23 |
| 24 #if defined(OPENBSD) || defined(FREEBSD) || defined(DRAGONFLY) |
| 25 #include <pthread_np.h> |
| 26 #endif |
| 27 |
24 #ifdef SYMBIAN | 28 #ifdef SYMBIAN |
25 /* In Open C sched_get_priority_min/max do not work properly, so we undefine | 29 /* In Open C sched_get_priority_min/max do not work properly, so we undefine |
26 * _POSIX_THREAD_PRIORITY_SCHEDULING here. | 30 * _POSIX_THREAD_PRIORITY_SCHEDULING here. |
27 */ | 31 */ |
28 #undef _POSIX_THREAD_PRIORITY_SCHEDULING | 32 #undef _POSIX_THREAD_PRIORITY_SCHEDULING |
29 #endif | 33 #endif |
30 | 34 |
31 #ifdef _PR_NICE_PRIORITY_SCHEDULING | 35 #ifdef _PR_NICE_PRIORITY_SCHEDULING |
32 #undef _POSIX_THREAD_PRIORITY_SCHEDULING | 36 #undef _POSIX_THREAD_PRIORITY_SCHEDULING |
33 #include <sys/resource.h> | 37 #include <sys/resource.h> |
(...skipping 1692 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1726 PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS, ("End PR_GetSP %p \n", top_sp)); | 1730 PR_LOG(_pr_gc_lm, PR_LOG_ALWAYS, ("End PR_GetSP %p \n", top_sp)); |
1727 return top_sp; | 1731 return top_sp; |
1728 } /* PR_GetSP */ | 1732 } /* PR_GetSP */ |
1729 | 1733 |
1730 #endif /* !defined(_PR_DCETHREADS) */ | 1734 #endif /* !defined(_PR_DCETHREADS) */ |
1731 | 1735 |
1732 PR_IMPLEMENT(PRStatus) PR_SetCurrentThreadName(const char *name) | 1736 PR_IMPLEMENT(PRStatus) PR_SetCurrentThreadName(const char *name) |
1733 { | 1737 { |
1734 PRThread *thread; | 1738 PRThread *thread; |
1735 size_t nameLen; | 1739 size_t nameLen; |
1736 int result; | 1740 int result = 0; |
1737 | 1741 |
1738 if (!name) { | 1742 if (!name) { |
1739 PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0); | 1743 PR_SetError(PR_INVALID_ARGUMENT_ERROR, 0); |
1740 return PR_FAILURE; | 1744 return PR_FAILURE; |
1741 } | 1745 } |
1742 | 1746 |
1743 thread = PR_GetCurrentThread(); | 1747 thread = PR_GetCurrentThread(); |
1744 if (!thread) | 1748 if (!thread) |
1745 return PR_FAILURE; | 1749 return PR_FAILURE; |
1746 | 1750 |
1747 PR_Free(thread->name); | 1751 PR_Free(thread->name); |
1748 nameLen = strlen(name); | 1752 nameLen = strlen(name); |
1749 thread->name = (char *)PR_Malloc(nameLen + 1); | 1753 thread->name = (char *)PR_Malloc(nameLen + 1); |
1750 if (!thread->name) | 1754 if (!thread->name) |
1751 return PR_FAILURE; | 1755 return PR_FAILURE; |
1752 memcpy(thread->name, name, nameLen + 1); | 1756 memcpy(thread->name, name, nameLen + 1); |
1753 | 1757 |
1754 #if defined(OPENBSD) || defined(FREEBSD) | 1758 #if defined(OPENBSD) || defined(FREEBSD) || defined(DRAGONFLY) |
1755 result = pthread_set_name_np(thread->id, name); | 1759 pthread_set_name_np(thread->id, name); |
| 1760 #elif defined(NETBSD) |
| 1761 result = pthread_setname_np(thread->id, "%s", (void *)name); |
1756 #else /* not BSD */ | 1762 #else /* not BSD */ |
1757 /* | 1763 /* |
1758 * On OSX, pthread_setname_np is only available in 10.6 or later, so test | 1764 * On OSX, pthread_setname_np is only available in 10.6 or later, so test |
1759 * for it at runtime. It also may not be available on all linux distros. | 1765 * for it at runtime. It also may not be available on all linux distros. |
1760 */ | 1766 */ |
1761 #if defined(DARWIN) | 1767 #if defined(DARWIN) |
1762 int (*dynamic_pthread_setname_np)(const char*); | 1768 int (*dynamic_pthread_setname_np)(const char*); |
1763 #else | 1769 #else |
1764 int (*dynamic_pthread_setname_np)(pthread_t, const char*); | 1770 int (*dynamic_pthread_setname_np)(pthread_t, const char*); |
1765 #endif | 1771 #endif |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1807 PR_IMPLEMENT(const char *) PR_GetThreadName(const PRThread *thread) | 1813 PR_IMPLEMENT(const char *) PR_GetThreadName(const PRThread *thread) |
1808 { | 1814 { |
1809 if (!thread) | 1815 if (!thread) |
1810 return NULL; | 1816 return NULL; |
1811 return thread->name; | 1817 return thread->name; |
1812 } | 1818 } |
1813 | 1819 |
1814 #endif /* defined(_PR_PTHREADS) || defined(_PR_DCETHREADS) */ | 1820 #endif /* defined(_PR_PTHREADS) || defined(_PR_DCETHREADS) */ |
1815 | 1821 |
1816 /* ptthread.c */ | 1822 /* ptthread.c */ |
OLD | NEW |