diff options
author | mmentovai@google.com <mmentovai@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-08 16:19:43 +0000 |
---|---|---|
committer | mmentovai@google.com <mmentovai@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2008-08-08 16:19:43 +0000 |
commit | 08048c71997f7ec047f20fb0132db3884bada97d (patch) | |
tree | ea1aa92547415c6597ad15b37590887cb28a2316 /base/lock_impl.h | |
parent | 7fc9f719bfd04c02539cab7ca5da4fdc3eda588e (diff) | |
download | chromium_src-08048c71997f7ec047f20fb0132db3884bada97d.zip chromium_src-08048c71997f7ec047f20fb0132db3884bada97d.tar.gz chromium_src-08048c71997f7ec047f20fb0132db3884bada97d.tar.bz2 |
Port LockImpl, Lock, and ConditionVariable to pthreads-supporting platforms.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@567 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/lock_impl.h')
-rw-r--r-- | base/lock_impl.h | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/base/lock_impl.h b/base/lock_impl.h index 331bdc6..a33f107 100644 --- a/base/lock_impl.h +++ b/base/lock_impl.h @@ -27,22 +27,30 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -#ifndef BASE_LOCK_IMPL_H__ -#define BASE_LOCK_IMPL_H__ +#ifndef BASE_LOCK_IMPL_H_ +#define BASE_LOCK_IMPL_H_ -#include "base/basictypes.h" +#include "build/build_config.h" -#if defined(WIN32) -#include <Windows.h> -#elif defined(__APPLE__) -#include <libkern/OSAtomic.h> +#if defined(OS_WIN) +#include <windows.h> +#elif defined(OS_POSIX) +#include <pthread.h> #endif +#include "base/basictypes.h" + // This class implements the underlying platform-specific spin-lock mechanism // used for the Lock class. Most users should not use LockImpl directly, but // should instead use Lock. class LockImpl { public: +#if defined(OS_WIN) + typedef CRITICAL_SECTION OSLockType; +#elif defined(OS_POSIX) + typedef pthread_mutex_t OSLockType; +#endif + LockImpl(); ~LockImpl(); @@ -57,14 +65,15 @@ class LockImpl { // a successful call to Try, or a call to Lock. void Unlock(); + // Return the native underlying lock. + // TODO(awalker): refactor lock and condition variables so that this is + // unnecessary. + OSLockType* os_lock() { return &os_lock_; } + private: -#if defined(WIN32) - CRITICAL_SECTION critical_section_; -#elif defined(__APPLE__) - OSSpinLock spin_lock_; -#endif + OSLockType os_lock_; - DISALLOW_EVIL_CONSTRUCTORS(LockImpl); + DISALLOW_COPY_AND_ASSIGN(LockImpl); }; class AutoLockImpl { @@ -84,4 +93,4 @@ class AutoLockImpl { LockImpl* lock_impl_; }; -#endif // BASE_LOCK_IMPL_H__ +#endif // BASE_LOCK_IMPL_H_ |