pbos | 12411ef | 2015-11-23 14:47:56 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. |
| 3 | * |
| 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 |
| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 11 | #ifndef RTC_BASE_PLATFORM_THREAD_TYPES_H_ |
| 12 | #define RTC_BASE_PLATFORM_THREAD_TYPES_H_ |
pbos | 12411ef | 2015-11-23 14:47:56 -0800 | [diff] [blame] | 13 | |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 14 | // clang-format off |
| 15 | // clang formating would change include order. |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 16 | #if defined(WEBRTC_WIN) |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 17 | // Include winsock2.h before including <windows.h> to maintain consistency with |
| 18 | // win32.h. To include win32.h directly, it must be broken out into its own |
| 19 | // build target. |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 20 | #include <winsock2.h> |
| 21 | #include <windows.h> |
Sergey Ulanov | 6acefdb | 2017-12-11 17:38:13 -0800 | [diff] [blame] | 22 | #elif defined(WEBRTC_FUCHSIA) |
| 23 | #include <zircon/types.h> |
Tommi | 1f3f3c2 | 2018-02-17 11:46:14 +0100 | [diff] [blame] | 24 | #include <zircon/process.h> |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 25 | #elif defined(WEBRTC_POSIX) |
| 26 | #include <pthread.h> |
| 27 | #include <unistd.h> |
Oskar Sundbom | 13471a4 | 2019-03-01 16:11:49 +0100 | [diff] [blame] | 28 | #if defined(WEBRTC_MAC) |
| 29 | #include <pthread_spis.h> |
| 30 | #endif |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 31 | #endif |
Yves Gerey | 665174f | 2018-06-19 15:03:05 +0200 | [diff] [blame] | 32 | // clang-format on |
pbos | 12411ef | 2015-11-23 14:47:56 -0800 | [diff] [blame] | 33 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 34 | namespace rtc { |
| 35 | #if defined(WEBRTC_WIN) |
| 36 | typedef DWORD PlatformThreadId; |
| 37 | typedef DWORD PlatformThreadRef; |
Sergey Ulanov | 6acefdb | 2017-12-11 17:38:13 -0800 | [diff] [blame] | 38 | #elif defined(WEBRTC_FUCHSIA) |
| 39 | typedef zx_handle_t PlatformThreadId; |
Tommi | f017980 | 2018-02-17 15:00:39 +0100 | [diff] [blame] | 40 | typedef zx_handle_t PlatformThreadRef; |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 41 | #elif defined(WEBRTC_POSIX) |
| 42 | typedef pid_t PlatformThreadId; |
| 43 | typedef pthread_t PlatformThreadRef; |
| 44 | #endif |
Tommi | 1f3f3c2 | 2018-02-17 11:46:14 +0100 | [diff] [blame] | 45 | |
| 46 | // Retrieve the ID of the current thread. |
| 47 | PlatformThreadId CurrentThreadId(); |
| 48 | |
| 49 | // Retrieves a reference to the current thread. On Windows, this is the same |
| 50 | // as CurrentThreadId. On other platforms it's the pthread_t returned by |
| 51 | // pthread_self(). |
| 52 | PlatformThreadRef CurrentThreadRef(); |
| 53 | |
| 54 | // Compares two thread identifiers for equality. |
| 55 | bool IsThreadRefEqual(const PlatformThreadRef& a, const PlatformThreadRef& b); |
| 56 | |
| 57 | // Sets the current thread name. |
| 58 | void SetCurrentThreadName(const char* name); |
| 59 | |
Henrik Kjellander | ec78f1c | 2017-06-29 07:52:50 +0200 | [diff] [blame] | 60 | } // namespace rtc |
pbos | 12411ef | 2015-11-23 14:47:56 -0800 | [diff] [blame] | 61 | |
Mirko Bonadei | 92ea95e | 2017-09-15 06:47:31 +0200 | [diff] [blame] | 62 | #endif // RTC_BASE_PLATFORM_THREAD_TYPES_H_ |