| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // WARNING: You should *NOT* be using this class directly. PlatformThread is | 5 // WARNING: You should *NOT* be using this class directly. PlatformThread is |
| 6 // the low-level platform-specific abstraction to the OS's threading interface. | 6 // the low-level platform-specific abstraction to the OS's threading interface. |
| 7 // You should instead be using a message-loop driven Thread, see thread.h. | 7 // You should instead be using a message-loop driven Thread, see thread.h. |
| 8 | 8 |
| 9 #ifndef BASE_THREADING_PLATFORM_THREAD_H_ | 9 #ifndef BASE_THREADING_PLATFORM_THREAD_H_ |
| 10 #define BASE_THREADING_PLATFORM_THREAD_H_ | 10 #define BASE_THREADING_PLATFORM_THREAD_H_ |
| 11 | 11 |
| 12 #include <stddef.h> | 12 #include <stddef.h> |
| 13 | 13 |
| 14 #include "base/base_export.h" | 14 #include "base/base_export.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/time/time.h" | 16 #include "base/time/time.h" |
| 17 #include "build/build_config.h" | 17 #include "build/build_config.h" |
| 18 | 18 |
| 19 #if defined(OS_WIN) | 19 #if defined(OS_WIN) |
| 20 #include <windows.h> | 20 #include <windows.h> |
| 21 #elif defined(OS_MACOSX) | 21 #elif defined(OS_MACOSX) |
| 22 #include <mach/mach_types.h> | 22 #include <mach/mach_types.h> |
| 23 #elif defined(OS_POSIX) | 23 #elif defined(OS_POSIX) |
| 24 #include <pthread.h> | 24 #include <pthread.h> |
| 25 #include <unistd.h> | 25 #include <unistd.h> |
| 26 #elif defined(OS_FUCHSIA) |
| 27 #include <threads.h> |
| 26 #endif | 28 #endif |
| 27 | 29 |
| 28 namespace base { | 30 namespace base { |
| 29 | 31 |
| 30 // Used for logging. Always an integer value. | 32 // Used for logging. Always an integer value. |
| 31 #if defined(OS_WIN) | 33 #if defined(OS_WIN) |
| 32 typedef DWORD PlatformThreadId; | 34 typedef DWORD PlatformThreadId; |
| 33 #elif defined(OS_MACOSX) | 35 #elif defined(OS_MACOSX) |
| 34 typedef mach_port_t PlatformThreadId; | 36 typedef mach_port_t PlatformThreadId; |
| 35 #elif defined(OS_POSIX) | 37 #elif defined(OS_POSIX) |
| 36 typedef pid_t PlatformThreadId; | 38 typedef pid_t PlatformThreadId; |
| 39 #elif defined(OS_FUCHSIA) |
| 40 typedef pid_t PlatformThreadId; |
| 37 #endif | 41 #endif |
| 38 | 42 |
| 39 // Used for thread checking and debugging. | 43 // Used for thread checking and debugging. |
| 40 // Meant to be as fast as possible. | 44 // Meant to be as fast as possible. |
| 41 // These are produced by PlatformThread::CurrentRef(), and used to later | 45 // These are produced by PlatformThread::CurrentRef(), and used to later |
| 42 // check if we are on the same thread or not by using ==. These are safe | 46 // check if we are on the same thread or not by using ==. These are safe |
| 43 // to copy between threads, but can't be copied to another process as they | 47 // to copy between threads, but can't be copied to another process as they |
| 44 // have no meaning there. Also, the internal identifier can be re-used | 48 // have no meaning there. Also, the internal identifier can be re-used |
| 45 // after a thread dies, so a PlatformThreadRef cannot be reliably used | 49 // after a thread dies, so a PlatformThreadRef cannot be reliably used |
| 46 // to distinguish a new thread from an old, dead thread. | 50 // to distinguish a new thread from an old, dead thread. |
| 47 class PlatformThreadRef { | 51 class PlatformThreadRef { |
| 48 public: | 52 public: |
| 49 #if defined(OS_WIN) | 53 #if defined(OS_WIN) |
| 50 typedef DWORD RefType; | 54 typedef DWORD RefType; |
| 51 #elif defined(OS_POSIX) | 55 #elif defined(OS_POSIX) |
| 52 typedef pthread_t RefType; | 56 typedef pthread_t RefType; |
| 57 #elif defined(OS_FUCHSIA) |
| 58 typedef thrd_t RefType; |
| 53 #endif | 59 #endif |
| 54 PlatformThreadRef() | 60 PlatformThreadRef() |
| 55 : id_(0) { | 61 : id_(0) { |
| 56 } | 62 } |
| 57 | 63 |
| 58 explicit PlatformThreadRef(RefType id) | 64 explicit PlatformThreadRef(RefType id) |
| 59 : id_(id) { | 65 : id_(id) { |
| 60 } | 66 } |
| 61 | 67 |
| 62 bool operator==(PlatformThreadRef other) const { | 68 bool operator==(PlatformThreadRef other) const { |
| 63 return id_ == other.id_; | 69 return id_ == other.id_; |
| 64 } | 70 } |
| 65 | 71 |
| 66 bool is_null() const { | 72 bool is_null() const { |
| 67 return id_ == 0; | 73 return id_ == 0; |
| 68 } | 74 } |
| 69 private: | 75 private: |
| 70 RefType id_; | 76 RefType id_; |
| 71 }; | 77 }; |
| 72 | 78 |
| 73 // Used to operate on threads. | 79 // Used to operate on threads. |
| 74 class PlatformThreadHandle { | 80 class PlatformThreadHandle { |
| 75 public: | 81 public: |
| 76 #if defined(OS_WIN) | 82 #if defined(OS_WIN) |
| 77 typedef void* Handle; | 83 typedef void* Handle; |
| 78 #elif defined(OS_POSIX) | 84 #elif defined(OS_POSIX) |
| 79 typedef pthread_t Handle; | 85 typedef pthread_t Handle; |
| 86 #elif defined(OS_FUCHSIA) |
| 87 typedef thrd_t Handle; |
| 80 #endif | 88 #endif |
| 81 | 89 |
| 82 PlatformThreadHandle() : handle_(0) {} | 90 PlatformThreadHandle() : handle_(0) {} |
| 83 | 91 |
| 84 explicit PlatformThreadHandle(Handle handle) : handle_(handle) {} | 92 explicit PlatformThreadHandle(Handle handle) : handle_(handle) {} |
| 85 | 93 |
| 86 bool is_equal(const PlatformThreadHandle& other) const { | 94 bool is_equal(const PlatformThreadHandle& other) const { |
| 87 return handle_ == other.handle_; | 95 return handle_ == other.handle_; |
| 88 } | 96 } |
| 89 | 97 |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 223 ThreadPriority priority); | 231 ThreadPriority priority); |
| 224 #endif | 232 #endif |
| 225 | 233 |
| 226 private: | 234 private: |
| 227 DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformThread); | 235 DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformThread); |
| 228 }; | 236 }; |
| 229 | 237 |
| 230 } // namespace base | 238 } // namespace base |
| 231 | 239 |
| 232 #endif // BASE_THREADING_PLATFORM_THREAD_H_ | 240 #endif // BASE_THREADING_PLATFORM_THREAD_H_ |
| OLD | NEW |