forked from AlexanderBabansky/rtaudio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.h
More file actions
41 lines (36 loc) · 1.05 KB
/
utils.h
File metadata and controls
41 lines (36 loc) · 1.05 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
#pragma once
#include <string>
std::string convertCharPointerToStdString(const wchar_t* text);
std::string convertCharPointerToStdString(const char* text);
std::wstring convertStdStringToWString(const std::string& text);
#if defined(_MSC_VER)
#define MUTEX_INITIALIZE(A) InitializeCriticalSection(A)
#define MUTEX_DESTROY(A) DeleteCriticalSection(A)
#define MUTEX_LOCK(A) EnterCriticalSection(A)
#define MUTEX_UNLOCK(A) LeaveCriticalSection(A)
#else
#define MUTEX_INITIALIZE(A) pthread_mutex_init(A, NULL)
#define MUTEX_DESTROY(A) pthread_mutex_destroy(A)
#define MUTEX_LOCK(A) pthread_mutex_lock(A)
#define MUTEX_UNLOCK(A) pthread_mutex_unlock(A)
#endif
#define SAFE_RELEASE( objectPtr )\
if ( objectPtr )\
{\
objectPtr->Release();\
objectPtr = NULL;\
}
template<class A>
class MutexRaii{
public:
MutexRaii(A& a) : mMutex(a){
MUTEX_LOCK(&mMutex);
}
~MutexRaii(){
MUTEX_UNLOCK(&mMutex);
}
MutexRaii(const MutexRaii&) = delete;
MutexRaii& operator=(const MutexRaii&) = delete;
private:
A& mMutex;
};