mirror of
https://github.com/overte-org/overte.git
synced 2025-07-11 00:58:54 +02:00
use alias for unique_lock and mutex
This commit is contained in:
parent
3b56df6e99
commit
adf41fce19
2 changed files with 11 additions and 8 deletions
|
@ -21,7 +21,7 @@
|
||||||
AudioInjectorManager::~AudioInjectorManager() {
|
AudioInjectorManager::~AudioInjectorManager() {
|
||||||
_shouldStop = true;
|
_shouldStop = true;
|
||||||
|
|
||||||
std::unique_lock<std::mutex> lock(_injectorsMutex);
|
Lock lock(_injectorsMutex);
|
||||||
|
|
||||||
// make sure any still living injectors are stopped and deleted
|
// make sure any still living injectors are stopped and deleted
|
||||||
while (!_injectors.empty()) {
|
while (!_injectors.empty()) {
|
||||||
|
@ -61,7 +61,7 @@ void AudioInjectorManager::createThread() {
|
||||||
void AudioInjectorManager::run() {
|
void AudioInjectorManager::run() {
|
||||||
while (!_shouldStop) {
|
while (!_shouldStop) {
|
||||||
// wait until the next injector is ready, or until we get a new injector given to us
|
// wait until the next injector is ready, or until we get a new injector given to us
|
||||||
std::unique_lock<std::mutex> lock(_injectorsMutex);
|
Lock lock(_injectorsMutex);
|
||||||
|
|
||||||
if (_injectors.size() > 0) {
|
if (_injectors.size() > 0) {
|
||||||
// when does the next injector need to send a frame?
|
// when does the next injector need to send a frame?
|
||||||
|
@ -119,7 +119,7 @@ bool AudioInjectorManager::threadInjector(AudioInjector* injector) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// guard the injectors vector with a mutex
|
// guard the injectors vector with a mutex
|
||||||
std::unique_lock<std::mutex> lock(_injectorsMutex);
|
Lock lock(_injectorsMutex);
|
||||||
|
|
||||||
// check if we'll be able to thread this injector (do we have < max concurrent injectors)
|
// check if we'll be able to thread this injector (do we have < max concurrent injectors)
|
||||||
if (_injectors.size() < MAX_INJECTORS_PER_THREAD) {
|
if (_injectors.size() < MAX_INJECTORS_PER_THREAD) {
|
||||||
|
@ -150,7 +150,7 @@ bool AudioInjectorManager::threadInjector(AudioInjector* injector) {
|
||||||
void AudioInjectorManager::restartFinishedInjector(AudioInjector* injector) {
|
void AudioInjectorManager::restartFinishedInjector(AudioInjector* injector) {
|
||||||
if (!_shouldStop) {
|
if (!_shouldStop) {
|
||||||
// guard the injectors vector with a mutex
|
// guard the injectors vector with a mutex
|
||||||
std::unique_lock<std::mutex> lock(_injectorsMutex);
|
Lock lock(_injectorsMutex);
|
||||||
|
|
||||||
// add the injector to the queue with a send timestamp of now
|
// add the injector to the queue with a send timestamp of now
|
||||||
_injectors.emplace(usecTimestampNow(), InjectorQPointer { injector });
|
_injectors.emplace(usecTimestampNow(), InjectorQPointer { injector });
|
||||||
|
|
|
@ -24,9 +24,6 @@
|
||||||
#include <DependencyManager.h>
|
#include <DependencyManager.h>
|
||||||
|
|
||||||
class AudioInjector;
|
class AudioInjector;
|
||||||
using InjectorQPointer = QPointer<AudioInjector>;
|
|
||||||
using TimeInjectorPointerPair = std::pair<uint64_t, InjectorQPointer>;
|
|
||||||
using InjectorQueue = std::queue<TimeInjectorPointerPair>;
|
|
||||||
|
|
||||||
class AudioInjectorManager : public QObject, public Dependency {
|
class AudioInjectorManager : public QObject, public Dependency {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
@ -36,6 +33,12 @@ public:
|
||||||
private slots:
|
private slots:
|
||||||
void run();
|
void run();
|
||||||
private:
|
private:
|
||||||
|
using InjectorQPointer = QPointer<AudioInjector>;
|
||||||
|
using TimeInjectorPointerPair = std::pair<uint64_t, InjectorQPointer>;
|
||||||
|
using InjectorQueue = std::queue<TimeInjectorPointerPair>;
|
||||||
|
using Mutex = std::mutex;
|
||||||
|
using Lock = std::unique_lock<Mutex>;
|
||||||
|
|
||||||
bool threadInjector(AudioInjector* injector);
|
bool threadInjector(AudioInjector* injector);
|
||||||
void restartFinishedInjector(AudioInjector* injector);
|
void restartFinishedInjector(AudioInjector* injector);
|
||||||
void notifyInjectorReadyCondition() { _injectorReady.notify_one(); }
|
void notifyInjectorReadyCondition() { _injectorReady.notify_one(); }
|
||||||
|
@ -49,7 +52,7 @@ private:
|
||||||
QThread* _thread { nullptr };
|
QThread* _thread { nullptr };
|
||||||
bool _shouldStop { false };
|
bool _shouldStop { false };
|
||||||
InjectorQueue _injectors;
|
InjectorQueue _injectors;
|
||||||
std::mutex _injectorsMutex;
|
Mutex _injectorsMutex;
|
||||||
std::condition_variable _injectorReady;
|
std::condition_variable _injectorReady;
|
||||||
|
|
||||||
friend class AudioInjector;
|
friend class AudioInjector;
|
||||||
|
|
Loading…
Reference in a new issue