| OLD | NEW |
| 1 // Copyright (c) 2010 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_ |
| 11 #pragma once | 11 #pragma once |
| 12 | 12 |
| 13 #include "base/base_api.h" |
| 13 #include "base/basictypes.h" | 14 #include "base/basictypes.h" |
| 14 #include "build/build_config.h" | 15 #include "build/build_config.h" |
| 15 | 16 |
| 16 #if defined(OS_WIN) | 17 #if defined(OS_WIN) |
| 17 #include <windows.h> | 18 #include <windows.h> |
| 18 #elif defined(OS_POSIX) | 19 #elif defined(OS_POSIX) |
| 19 #include <pthread.h> | 20 #include <pthread.h> |
| 20 #if defined(OS_MACOSX) | 21 #if defined(OS_MACOSX) |
| 21 #include <mach/mach.h> | 22 #include <mach/mach.h> |
| 22 #else // OS_POSIX && !OS_MACOSX | 23 #else // OS_POSIX && !OS_MACOSX |
| (...skipping 17 matching lines...) Expand all Loading... |
| 40 #if defined(OS_MACOSX) | 41 #if defined(OS_MACOSX) |
| 41 typedef mach_port_t PlatformThreadId; | 42 typedef mach_port_t PlatformThreadId; |
| 42 #else // OS_POSIX && !OS_MACOSX | 43 #else // OS_POSIX && !OS_MACOSX |
| 43 typedef pid_t PlatformThreadId; | 44 typedef pid_t PlatformThreadId; |
| 44 #endif | 45 #endif |
| 45 #endif | 46 #endif |
| 46 | 47 |
| 47 const PlatformThreadId kInvalidThreadId = 0; | 48 const PlatformThreadId kInvalidThreadId = 0; |
| 48 | 49 |
| 49 // A namespace for low-level thread functions. | 50 // A namespace for low-level thread functions. |
| 50 class PlatformThread { | 51 class BASE_API PlatformThread { |
| 51 public: | 52 public: |
| 52 // Implement this interface to run code on a background thread. Your | 53 // Implement this interface to run code on a background thread. Your |
| 53 // ThreadMain method will be called on the newly created thread. | 54 // ThreadMain method will be called on the newly created thread. |
| 54 class Delegate { | 55 class BASE_API Delegate { |
| 55 public: | 56 public: |
| 56 virtual ~Delegate() {} | 57 virtual ~Delegate() {} |
| 57 virtual void ThreadMain() = 0; | 58 virtual void ThreadMain() = 0; |
| 58 }; | 59 }; |
| 59 | 60 |
| 60 // Gets the current thread id, which may be useful for logging purposes. | 61 // Gets the current thread id, which may be useful for logging purposes. |
| 61 static PlatformThreadId CurrentId(); | 62 static PlatformThreadId CurrentId(); |
| 62 | 63 |
| 63 // Yield the current thread so another thread can be scheduled. | 64 // Yield the current thread so another thread can be scheduled. |
| 64 static void YieldCurrentThread(); | 65 static void YieldCurrentThread(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 90 // |thread_handle|. | 91 // |thread_handle|. |
| 91 static void Join(PlatformThreadHandle thread_handle); | 92 static void Join(PlatformThreadHandle thread_handle); |
| 92 | 93 |
| 93 private: | 94 private: |
| 94 DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformThread); | 95 DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformThread); |
| 95 }; | 96 }; |
| 96 | 97 |
| 97 } // namespace base | 98 } // namespace base |
| 98 | 99 |
| 99 #endif // BASE_THREADING_PLATFORM_THREAD_H_ | 100 #endif // BASE_THREADING_PLATFORM_THREAD_H_ |
| OLD | NEW |