mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-05 05:42:53 +02:00
Merge branch 'tryLocker' into avatar
This commit is contained in:
commit
1c6db9c8cf
1 changed files with 31 additions and 0 deletions
31
libraries/shared/src/TryLocker.h
Normal file
31
libraries/shared/src/TryLocker.h
Normal 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
|
Loading…
Reference in a new issue