blob: 6b9101eec0d98772c3fdc842b8bfc7ca79a79853 [file] [log] [blame]
pbos12411ef2015-11-23 14:47:56 -08001/*
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 Bonadei92ea95e2017-09-15 06:47:31 +020011#ifndef RTC_BASE_PLATFORM_THREAD_TYPES_H_
12#define RTC_BASE_PLATFORM_THREAD_TYPES_H_
pbos12411ef2015-11-23 14:47:56 -080013
Yves Gerey665174f2018-06-19 15:03:05 +020014// clang-format off
15// clang formating would change include order.
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020016#if defined(WEBRTC_WIN)
Yves Gerey665174f2018-06-19 15:03:05 +020017// 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 Kjellanderec78f1c2017-06-29 07:52:50 +020020#include <winsock2.h>
21#include <windows.h>
Sergey Ulanov6acefdb2017-12-11 17:38:13 -080022#elif defined(WEBRTC_FUCHSIA)
23#include <zircon/types.h>
Tommi1f3f3c22018-02-17 11:46:14 +010024#include <zircon/process.h>
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020025#elif defined(WEBRTC_POSIX)
26#include <pthread.h>
27#include <unistd.h>
Oskar Sundbom13471a42019-03-01 16:11:49 +010028#if defined(WEBRTC_MAC)
29#include <pthread_spis.h>
30#endif
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020031#endif
Yves Gerey665174f2018-06-19 15:03:05 +020032// clang-format on
pbos12411ef2015-11-23 14:47:56 -080033
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020034namespace rtc {
35#if defined(WEBRTC_WIN)
36typedef DWORD PlatformThreadId;
37typedef DWORD PlatformThreadRef;
Sergey Ulanov6acefdb2017-12-11 17:38:13 -080038#elif defined(WEBRTC_FUCHSIA)
39typedef zx_handle_t PlatformThreadId;
Tommif0179802018-02-17 15:00:39 +010040typedef zx_handle_t PlatformThreadRef;
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020041#elif defined(WEBRTC_POSIX)
42typedef pid_t PlatformThreadId;
43typedef pthread_t PlatformThreadRef;
44#endif
Tommi1f3f3c22018-02-17 11:46:14 +010045
46// Retrieve the ID of the current thread.
47PlatformThreadId 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().
52PlatformThreadRef CurrentThreadRef();
53
54// Compares two thread identifiers for equality.
55bool IsThreadRefEqual(const PlatformThreadRef& a, const PlatformThreadRef& b);
56
57// Sets the current thread name.
58void SetCurrentThreadName(const char* name);
59
Henrik Kjellanderec78f1c2017-06-29 07:52:50 +020060} // namespace rtc
pbos12411ef2015-11-23 14:47:56 -080061
Mirko Bonadei92ea95e2017-09-15 06:47:31 +020062#endif // RTC_BASE_PLATFORM_THREAD_TYPES_H_