class Lock {
public:
Lock() : lock_() {}
~Lock() {}
void Acquire() { lock_.Lock(); }
void Release() { lock_.Unlock(); }
// If the lock is not held, take it and return true. If the lock is already
// held by another thread, immediately return false.
bool Try() { return lock_.Try(); }
// In debug builds this method checks that the lock has been acquired by the
// calling thread. If the lock has not been acquired, then the method
// will DCHECK(). In non-debug builds, the LockImpl's implementation of
// AssertAcquired() is an empty inline method.
void AssertAcquired() const { return lock_.AssertAcquired(); }
// Return the underlying lock implementation.
// TODO(awalker): refactor lock and condition variables so that this is
// unnecessary.
LockImpl* lock_impl() { return &lock_; }
private:
LockImpl lock_; // Platform specific underlying lock implementation.
DISALLOW_COPY_AND_ASSIGN(Lock);
};
不明白这个类为什么要使用委托,其实使用继承也可以实现一样的效果,可以少写很多代码