security/sandbox/chromium/base/synchronization/lock_impl.h

Fri, 16 Jan 2015 04:50:19 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 04:50:19 +0100
branch
TOR_BUG_9701
changeset 13
44a2da4a2ab2
permissions
-rw-r--r--

Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32

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

mercurial