| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_ |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 const PlatformThreadHandle kNullThreadHandle = 0; | 40 const PlatformThreadHandle kNullThreadHandle = 0; |
| 41 #if defined(OS_MACOSX) | 41 #if defined(OS_MACOSX) |
| 42 typedef mach_port_t PlatformThreadId; | 42 typedef mach_port_t PlatformThreadId; |
| 43 #else // OS_POSIX && !OS_MACOSX | 43 #else // OS_POSIX && !OS_MACOSX |
| 44 typedef pid_t PlatformThreadId; | 44 typedef pid_t PlatformThreadId; |
| 45 #endif | 45 #endif |
| 46 #endif | 46 #endif |
| 47 | 47 |
| 48 const PlatformThreadId kInvalidThreadId = 0; | 48 const PlatformThreadId kInvalidThreadId = 0; |
| 49 | 49 |
| 50 // Valid values for SetThreadPriority() |
| 51 enum ThreadPriority{ |
| 52 kThreadPriority_Normal, |
| 53 // Suitable for low-latency, glitch-resistant audio. |
| 54 kThreadPriority_RealtimeAudio |
| 55 }; |
| 56 |
| 50 // A namespace for low-level thread functions. | 57 // A namespace for low-level thread functions. |
| 51 class BASE_API PlatformThread { | 58 class BASE_API PlatformThread { |
| 52 public: | 59 public: |
| 53 // Implement this interface to run code on a background thread. Your | 60 // Implement this interface to run code on a background thread. Your |
| 54 // ThreadMain method will be called on the newly created thread. | 61 // ThreadMain method will be called on the newly created thread. |
| 55 class BASE_API Delegate { | 62 class BASE_API Delegate { |
| 56 public: | 63 public: |
| 57 virtual ~Delegate() {} | 64 virtual ~Delegate() {} |
| 58 virtual void ThreadMain() = 0; | 65 virtual void ThreadMain() = 0; |
| 59 }; | 66 }; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 84 // CreateNonJoinable() does the same thing as Create() except the thread | 91 // CreateNonJoinable() does the same thing as Create() except the thread |
| 85 // cannot be Join()'d. Therefore, it also does not output a | 92 // cannot be Join()'d. Therefore, it also does not output a |
| 86 // PlatformThreadHandle. | 93 // PlatformThreadHandle. |
| 87 static bool CreateNonJoinable(size_t stack_size, Delegate* delegate); | 94 static bool CreateNonJoinable(size_t stack_size, Delegate* delegate); |
| 88 | 95 |
| 89 // Joins with a thread created via the Create function. This function blocks | 96 // Joins with a thread created via the Create function. This function blocks |
| 90 // the caller until the designated thread exits. This will invalidate | 97 // the caller until the designated thread exits. This will invalidate |
| 91 // |thread_handle|. | 98 // |thread_handle|. |
| 92 static void Join(PlatformThreadHandle thread_handle); | 99 static void Join(PlatformThreadHandle thread_handle); |
| 93 | 100 |
| 101 static void SetThreadPriority(PlatformThreadHandle handle, |
| 102 ThreadPriority priority); |
| 103 |
| 94 private: | 104 private: |
| 95 DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformThread); | 105 DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformThread); |
| 96 }; | 106 }; |
| 97 | 107 |
| 98 } // namespace base | 108 } // namespace base |
| 99 | 109 |
| 100 #endif // BASE_THREADING_PLATFORM_THREAD_H_ | 110 #endif // BASE_THREADING_PLATFORM_THREAD_H_ |
| OLD | NEW |