1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/sandbox/chromium/base/synchronization/lock_impl.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,61 @@ 1.4 +// Copyright (c) 2011 The Chromium Authors. All rights reserved. 1.5 +// Use of this source code is governed by a BSD-style license that can be 1.6 +// found in the LICENSE file. 1.7 + 1.8 +#ifndef BASE_SYNCHRONIZATION_LOCK_IMPL_H_ 1.9 +#define BASE_SYNCHRONIZATION_LOCK_IMPL_H_ 1.10 + 1.11 +#include "build/build_config.h" 1.12 + 1.13 +#if defined(OS_WIN) 1.14 +#include <windows.h> 1.15 +#elif defined(OS_POSIX) 1.16 +#include <pthread.h> 1.17 +#endif 1.18 + 1.19 +#include "base/base_export.h" 1.20 +#include "base/basictypes.h" 1.21 + 1.22 +namespace base { 1.23 +namespace internal { 1.24 + 1.25 +// This class implements the underlying platform-specific spin-lock mechanism 1.26 +// used for the Lock class. Most users should not use LockImpl directly, but 1.27 +// should instead use Lock. 1.28 +class BASE_EXPORT LockImpl { 1.29 + public: 1.30 +#if defined(OS_WIN) 1.31 + typedef CRITICAL_SECTION NativeHandle; 1.32 +#elif defined(OS_POSIX) 1.33 + typedef pthread_mutex_t NativeHandle; 1.34 +#endif 1.35 + 1.36 + LockImpl(); 1.37 + ~LockImpl(); 1.38 + 1.39 + // If the lock is not held, take it and return true. If the lock is already 1.40 + // held by something else, immediately return false. 1.41 + bool Try(); 1.42 + 1.43 + // Take the lock, blocking until it is available if necessary. 1.44 + void Lock(); 1.45 + 1.46 + // Release the lock. This must only be called by the lock's holder: after 1.47 + // a successful call to Try, or a call to Lock. 1.48 + void Unlock(); 1.49 + 1.50 + // Return the native underlying lock. 1.51 + // TODO(awalker): refactor lock and condition variables so that this is 1.52 + // unnecessary. 1.53 + NativeHandle* native_handle() { return &native_handle_; } 1.54 + 1.55 + private: 1.56 + NativeHandle native_handle_; 1.57 + 1.58 + DISALLOW_COPY_AND_ASSIGN(LockImpl); 1.59 +}; 1.60 + 1.61 +} // namespace internal 1.62 +} // namespace base 1.63 + 1.64 +#endif // BASE_SYNCHRONIZATION_LOCK_IMPL_H_