1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #ifndef PPAPI_UTILITY_THREADING_LOCK_H_
6 #define PPAPI_UTILITY_THREADING_LOCK_H_
16 /// A simple wrapper around a platform-specific lock. See also AutoLock.
19 /// Creates a lock in the "not held" state.
22 /// Destroys the lock.
25 /// Acquires the lock, blocking if it's already held by a different thread.
26 /// The lock must not already be held on the current thread (i.e. recursive
27 /// locks are not supported).
29 /// Most callers should consider using an AutoLock instead to automatically
30 /// acquire and release the lock.
33 /// Releases the lock. This must be paired with a call to Acquire().
38 typedef CRITICAL_SECTION OSLockType
;
40 typedef pthread_mutex_t OSLockType
;
45 // Copy and assign not supported.
47 Lock
& operator=(const Lock
&);
50 /// A helper class that scopes holding a lock.
55 /// void DoSomething() {
56 /// pp::AutoLock lock(lock_);
57 /// ...do something with the lock held...
66 explicit AutoLock(Lock
& lock
) : lock_(lock
) {
77 // Copy and assign not supported.
78 AutoLock(const AutoLock
&);
79 AutoLock
& operator=(const AutoLock
&);
84 #endif // PPAPI_UTILITY_THREADING_LOCK_H_