| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_PLATFORM_THREAD_H_ | 9 #ifndef BASE_THREADING_PLATFORM_THREAD_H_ |
| 10 #define BASE_PLATFORM_THREAD_H_ | 10 #define BASE_THREADING_PLATFORM_THREAD_H_ |
| 11 #pragma once | 11 #pragma once |
| 12 | 12 |
| 13 #include "base/basictypes.h" | 13 #include "base/basictypes.h" |
| 14 #include "build/build_config.h" |
| 15 |
| 16 #if defined(OS_WIN) |
| 17 #include <windows.h> |
| 18 #elif defined(OS_POSIX) |
| 19 #include <pthread.h> |
| 20 #if defined(OS_MACOSX) |
| 21 #include <mach/mach.h> |
| 22 #else // OS_POSIX && !OS_MACOSX |
| 23 #include <unistd.h> |
| 24 #endif |
| 25 #endif |
| 26 |
| 27 namespace base { |
| 14 | 28 |
| 15 // PlatformThreadHandle should not be assumed to be a numeric type, since the | 29 // PlatformThreadHandle should not be assumed to be a numeric type, since the |
| 16 // standard intends to allow pthread_t to be a structure. This means you | 30 // standard intends to allow pthread_t to be a structure. This means you |
| 17 // should not initialize it to a value, like 0. If it's a member variable, the | 31 // should not initialize it to a value, like 0. If it's a member variable, the |
| 18 // constructor can safely "value initialize" using () in the initializer list. | 32 // constructor can safely "value initialize" using () in the initializer list. |
| 19 #if defined(OS_WIN) | 33 #if defined(OS_WIN) |
| 20 #include <windows.h> | |
| 21 typedef DWORD PlatformThreadId; | 34 typedef DWORD PlatformThreadId; |
| 22 typedef void* PlatformThreadHandle; // HANDLE | 35 typedef void* PlatformThreadHandle; // HANDLE |
| 23 const PlatformThreadHandle kNullThreadHandle = NULL; | 36 const PlatformThreadHandle kNullThreadHandle = NULL; |
| 24 #elif defined(OS_POSIX) | 37 #elif defined(OS_POSIX) |
| 25 #include <pthread.h> | |
| 26 typedef pthread_t PlatformThreadHandle; | 38 typedef pthread_t PlatformThreadHandle; |
| 27 const PlatformThreadHandle kNullThreadHandle = 0; | 39 const PlatformThreadHandle kNullThreadHandle = 0; |
| 28 #if defined(OS_MACOSX) | 40 #if defined(OS_MACOSX) |
| 29 #include <mach/mach.h> | |
| 30 typedef mach_port_t PlatformThreadId; | 41 typedef mach_port_t PlatformThreadId; |
| 31 #else // OS_POSIX && !OS_MACOSX | 42 #else // OS_POSIX && !OS_MACOSX |
| 32 #include <unistd.h> | |
| 33 typedef pid_t PlatformThreadId; | 43 typedef pid_t PlatformThreadId; |
| 34 #endif | 44 #endif |
| 35 #endif | 45 #endif |
| 36 | 46 |
| 37 const PlatformThreadId kInvalidThreadId = 0; | 47 const PlatformThreadId kInvalidThreadId = 0; |
| 38 | 48 |
| 39 // A namespace for low-level thread functions. | 49 // A namespace for low-level thread functions. |
| 40 class PlatformThread { | 50 class PlatformThread { |
| 41 public: | 51 public: |
| 42 // Implement this interface to run code on a background thread. Your | 52 // Implement this interface to run code on a background thread. Your |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 77 | 87 |
| 78 // Joins with a thread created via the Create function. This function blocks | 88 // Joins with a thread created via the Create function. This function blocks |
| 79 // the caller until the designated thread exits. This will invalidate | 89 // the caller until the designated thread exits. This will invalidate |
| 80 // |thread_handle|. | 90 // |thread_handle|. |
| 81 static void Join(PlatformThreadHandle thread_handle); | 91 static void Join(PlatformThreadHandle thread_handle); |
| 82 | 92 |
| 83 private: | 93 private: |
| 84 DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformThread); | 94 DISALLOW_IMPLICIT_CONSTRUCTORS(PlatformThread); |
| 85 }; | 95 }; |
| 86 | 96 |
| 87 #endif // BASE_PLATFORM_THREAD_H_ | 97 } // namespace base |
| 98 |
| 99 #endif // BASE_THREADING_PLATFORM_THREAD_H_ |
| OLD | NEW |