OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
(...skipping 19 matching lines...) Expand all Loading... |
30 ret = pthread_mach_thread_np(pthread_self()); | 30 ret = pthread_mach_thread_np(pthread_self()); |
31 #elif defined(WEBRTC_LINUX) | 31 #elif defined(WEBRTC_LINUX) |
32 ret = syscall(__NR_gettid); | 32 ret = syscall(__NR_gettid); |
33 #elif defined(WEBRTC_ANDROID) | 33 #elif defined(WEBRTC_ANDROID) |
34 ret = gettid(); | 34 ret = gettid(); |
35 #else | 35 #else |
36 // Default implementation for nacl and solaris. | 36 // Default implementation for nacl and solaris. |
37 ret = reinterpret_cast<pid_t>(pthread_self()); | 37 ret = reinterpret_cast<pid_t>(pthread_self()); |
38 #endif | 38 #endif |
39 #endif // defined(WEBRTC_POSIX) | 39 #endif // defined(WEBRTC_POSIX) |
40 DCHECK(ret); | 40 RTC_DCHECK(ret); |
41 return ret; | 41 return ret; |
42 } | 42 } |
43 | 43 |
44 PlatformThreadRef CurrentThreadRef() { | 44 PlatformThreadRef CurrentThreadRef() { |
45 #if defined(WEBRTC_WIN) | 45 #if defined(WEBRTC_WIN) |
46 return GetCurrentThreadId(); | 46 return GetCurrentThreadId(); |
47 #elif defined(WEBRTC_POSIX) | 47 #elif defined(WEBRTC_POSIX) |
48 return pthread_self(); | 48 return pthread_self(); |
49 #endif | 49 #endif |
50 } | 50 } |
51 | 51 |
52 bool IsThreadRefEqual(const PlatformThreadRef& a, const PlatformThreadRef& b) { | 52 bool IsThreadRefEqual(const PlatformThreadRef& a, const PlatformThreadRef& b) { |
53 #if defined(WEBRTC_WIN) | 53 #if defined(WEBRTC_WIN) |
54 return a == b; | 54 return a == b; |
55 #elif defined(WEBRTC_POSIX) | 55 #elif defined(WEBRTC_POSIX) |
56 return pthread_equal(a, b); | 56 return pthread_equal(a, b); |
57 #endif | 57 #endif |
58 } | 58 } |
59 | 59 |
60 void SetCurrentThreadName(const char* name) { | 60 void SetCurrentThreadName(const char* name) { |
61 DCHECK(strlen(name) < 64); | 61 RTC_DCHECK(strlen(name) < 64); |
62 #if defined(WEBRTC_WIN) | 62 #if defined(WEBRTC_WIN) |
63 struct { | 63 struct { |
64 DWORD dwType; | 64 DWORD dwType; |
65 LPCSTR szName; | 65 LPCSTR szName; |
66 DWORD dwThreadID; | 66 DWORD dwThreadID; |
67 DWORD dwFlags; | 67 DWORD dwFlags; |
68 } threadname_info = {0x1000, name, static_cast<DWORD>(-1), 0}; | 68 } threadname_info = {0x1000, name, static_cast<DWORD>(-1), 0}; |
69 | 69 |
70 __try { | 70 __try { |
71 ::RaiseException(0x406D1388, 0, sizeof(threadname_info) / sizeof(DWORD), | 71 ::RaiseException(0x406D1388, 0, sizeof(threadname_info) / sizeof(DWORD), |
72 reinterpret_cast<ULONG_PTR*>(&threadname_info)); | 72 reinterpret_cast<ULONG_PTR*>(&threadname_info)); |
73 } __except (EXCEPTION_EXECUTE_HANDLER) { | 73 } __except (EXCEPTION_EXECUTE_HANDLER) { |
74 } | 74 } |
75 #elif defined(WEBRTC_LINUX) || defined(WEBRTC_ANDROID) | 75 #elif defined(WEBRTC_LINUX) || defined(WEBRTC_ANDROID) |
76 prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(name)); | 76 prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(name)); |
77 #elif defined(WEBRTC_MAC) || defined(WEBRTC_IOS) | 77 #elif defined(WEBRTC_MAC) || defined(WEBRTC_IOS) |
78 pthread_setname_np(name); | 78 pthread_setname_np(name); |
79 #endif | 79 #endif |
80 } | 80 } |
81 | 81 |
82 } // namespace rtc | 82 } // namespace rtc |
OLD | NEW |