基于qt,msvc2017-64bits,ffmpeg.opengl的播放器
zhangmeng
2021-03-03 4a6d9312cc1c9d62d66c4def71246d9faae29edb
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
#include "Mutex.h"
 
Mutex::Mutex()
{
#if defined(WIN32)
    m_mutex = ::CreateMutex(NULL, FALSE, NULL);
#else
    pthread_mutex_init(&mutex, NULL);
#endif
 
}
 
Mutex::~Mutex()
{
#if defined(WIN32)
    ::CloseHandle(m_mutex);
#else
     pthread_mutex_destroy(&mutex);
#endif
 
}
 
int Mutex::Lock() const
{
#if defined(WIN32)
    DWORD ret = WaitForSingleObject(m_mutex, INFINITE);
#else
    int ret = pthread_mutex_lock((pthread_mutex_t*)&mutex);
#endif
 
    return ret;
 
}
 
int Mutex::Unlock() const
{
#if defined(WIN32)
    bool ret = ::ReleaseMutex(m_mutex);
#else
    int ret = pthread_mutex_unlock((pthread_mutex_t*)&mutex);
#endif
    return ret;
}