Merge branch 'tryLocker' into avatar

This commit is contained in:
Brad Davis 2015-03-17 11:50:08 -07:00
commit 1c6db9c8cf

View file

@ -0,0 +1,31 @@
//
// TryLocker.h
// libraries/shared/src
//
// Created by Brad Davis on 2015/03/16.
// Copyright 2015 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_TryLocker_h
#define hifi_TryLocker_h
#include <QMutex>
class MutexTryLocker {
QMutex & _mutex;
bool _locked{false};
public:
MutexTryLocker(QMutex &m) : _mutex(m) {}
~MutexTryLocker() { if (_locked) _mutex.unlock(); }
bool tryLock() {
if (_locked) {
return true;
}
return (_locked = _mutex.tryLock());
}
}
#endif // hifi_UUID_h