-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreadingUtility.h
More file actions
46 lines (41 loc) · 1.29 KB
/
Copy pathThreadingUtility.h
File metadata and controls
46 lines (41 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
/**************************************************
Zlib Copyright 2015 Daniel "MonzUn" Bengtsson
***************************************************/
#pragma once
#include <thread>
#include <mutex>
#include "Logger.h"
namespace ThreadingUtility
{
/// <summary>
/// Checks if the inputed thread is joinable and if so, joins it.
/// </summary>
/// <param name="thread">The thread to join.</param>
static void JoinThread( std::thread& thread ) {
if ( thread.joinable() ) {
thread.join();
} else {
Logger::Log( "Attempted to join unjoinable thread", "ThreadingUtility", LogSeverity::WARNING_MSG );
}
}
static void LockMutexes( std::initializer_list <std::mutex*> mutexes ) {
for ( auto& mutex : mutexes ) {
mutex->lock();
}
}
// TODODB: Investigate possibility of variadic function to avoid having to add extra curly braces on this call
static void UnlockMutexes( std::initializer_list<std::mutex*> mutexes ) {
for ( auto& mutex : mutexes ) {
mutex->unlock();
}
}
template<typename Lockable>
static void UnlockMutexesVariadic( Lockable& lockable ) {
lockable.unlock();
}
template<typename Lockable1, typename... LockableN>
static void UnlockMutexesVariadic( Lockable1& lockable1, LockableN&... lockableN ) {
UnlockMutexesVariadic( lockableN ... );
lockable1.unlock();
}
}