| 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 #ifndef BASE_SYNCHRONIZATION_LOCK_IMPL_H_ | 5 #ifndef BASE_SYNCHRONIZATION_LOCK_IMPL_H_ |
| 6 #define BASE_SYNCHRONIZATION_LOCK_IMPL_H_ | 6 #define BASE_SYNCHRONIZATION_LOCK_IMPL_H_ |
| 7 | 7 |
| 8 #include "build/build_config.h" | 8 #include "build/build_config.h" |
| 9 | 9 |
| 10 #if defined(OS_WIN) | 10 #if defined(OS_WIN) |
| 11 #include <windows.h> | 11 #include <windows.h> |
| 12 #elif defined(OS_POSIX) | 12 #elif defined(OS_POSIX) |
| 13 #include <pthread.h> | 13 #include <pthread.h> |
| 14 #endif | 14 #endif |
| 15 | 15 |
| 16 #include "base/base_export.h" | 16 #include "base/base_export.h" |
| 17 #include "base/basictypes.h" | 17 #include "base/basictypes.h" |
| 18 | 18 |
| 19 namespace base { | 19 namespace base { |
| 20 namespace internal { | 20 namespace internal { |
| 21 | 21 |
| 22 // This class implements the underlying platform-specific spin-lock mechanism | 22 // This class implements the underlying platform-specific spin-lock mechanism |
| 23 // used for the Lock class. Most users should not use LockImpl directly, but | 23 // used for the Lock class. Most users should not use LockImpl directly, but |
| 24 // should instead use Lock. | 24 // should instead use Lock. |
| 25 class BASE_EXPORT LockImpl { | 25 class BASE_EXPORT LockImpl { |
| 26 public: | 26 public: |
| 27 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
| 28 typedef CRITICAL_SECTION OSLockType; | 28 typedef CRITICAL_SECTION NativeHandle; |
| 29 #elif defined(OS_POSIX) | 29 #elif defined(OS_POSIX) |
| 30 typedef pthread_mutex_t OSLockType; | 30 typedef pthread_mutex_t NativeHandle; |
| 31 #endif | 31 #endif |
| 32 | 32 |
| 33 LockImpl(); | 33 LockImpl(); |
| 34 ~LockImpl(); | 34 ~LockImpl(); |
| 35 | 35 |
| 36 // If the lock is not held, take it and return true. If the lock is already | 36 // If the lock is not held, take it and return true. If the lock is already |
| 37 // held by something else, immediately return false. | 37 // held by something else, immediately return false. |
| 38 bool Try(); | 38 bool Try(); |
| 39 | 39 |
| 40 // Take the lock, blocking until it is available if necessary. | 40 // Take the lock, blocking until it is available if necessary. |
| 41 void Lock(); | 41 void Lock(); |
| 42 | 42 |
| 43 // Release the lock. This must only be called by the lock's holder: after | 43 // Release the lock. This must only be called by the lock's holder: after |
| 44 // a successful call to Try, or a call to Lock. | 44 // a successful call to Try, or a call to Lock. |
| 45 void Unlock(); | 45 void Unlock(); |
| 46 | 46 |
| 47 // Return the native underlying lock. | 47 // Return the native underlying lock. |
| 48 // TODO(awalker): refactor lock and condition variables so that this is | 48 // TODO(awalker): refactor lock and condition variables so that this is |
| 49 // unnecessary. | 49 // unnecessary. |
| 50 OSLockType* os_lock() { return &os_lock_; } | 50 NativeHandle* native_handle() { return &native_handle_; } |
| 51 | 51 |
| 52 private: | 52 private: |
| 53 OSLockType os_lock_; | 53 NativeHandle native_handle_; |
| 54 | 54 |
| 55 DISALLOW_COPY_AND_ASSIGN(LockImpl); | 55 DISALLOW_COPY_AND_ASSIGN(LockImpl); |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 } // namespace internal | 58 } // namespace internal |
| 59 } // namespace base | 59 } // namespace base |
| 60 | 60 |
| 61 #endif // BASE_SYNCHRONIZATION_LOCK_IMPL_H_ | 61 #endif // BASE_SYNCHRONIZATION_LOCK_IMPL_H_ |
| OLD | NEW |