Files
oemcrypto/util/include/lock.h
Fred Gylys-Colwell 61f02edda4 Refactor
This renames the "mock" code to "reference" because that's really what
it is.  Also, some code has been moved from the CDM repo to a common
utility directory so that it can be included here, and the oemcrypto
unit tests can now be built without having access to a current CDM
repo.

There are no functionality changes in this CL.
2018-05-10 15:28:20 -07:00

52 lines
1.0 KiB
C++

// Copyright 2013 Google Inc. All Rights Reserved.
//
// Lock - Platform independent interface for a Mutex class
//
#ifndef WVCDM_UTIL_LOCK_H_
#define WVCDM_UTIL_LOCK_H_
#include "disallow_copy_and_assign.h"
namespace wvcdm {
// Simple lock class. The implementation is platform dependent.
//
// The lock must be unlocked by the thread that locked it.
// The lock is also not recursive (ie. cannot be taken multiple times).
class Lock {
public:
Lock();
~Lock();
void Acquire();
void Release();
friend class AutoLock;
private:
class Impl;
Impl* impl_;
CORE_DISALLOW_COPY_AND_ASSIGN(Lock);
};
// Manages the lock automatically. It will be locked when AutoLock
// is constructed and release when AutoLock goes out of scope.
class AutoLock {
public:
explicit AutoLock(Lock& lock) : lock_(&lock) { lock_->Acquire(); }
explicit AutoLock(Lock* lock) : lock_(lock) { lock_->Acquire(); }
~AutoLock() { lock_->Release(); }
private:
Lock* lock_;
CORE_DISALLOW_COPY_AND_ASSIGN(AutoLock);
};
} // namespace wvcdm
#endif // WVCDM_UTIL_LOCK_H_