From 08048c71997f7ec047f20fb0132db3884bada97d Mon Sep 17 00:00:00 2001 From: "mmentovai@google.com" Date: Fri, 8 Aug 2008 16:19:43 +0000 Subject: 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 --- base/lock_impl.h | 37 +++++++++++++++++++++++-------------- 1 file changed, 23 insertions(+), 14 deletions(-) (limited to 'base/lock_impl.h') 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 -#elif defined(__APPLE__) -#include +#if defined(OS_WIN) +#include +#elif defined(OS_POSIX) +#include #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_ -- cgit v1.1