-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththread_defs2.cpp
51 lines (43 loc) · 1.22 KB
/
thread_defs2.cpp
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
47
48
49
50
51
/*********************************************************************************
INTEL CORPORATION PROPRIETARY INFORMATION
This software is supplied under the terms of a license agreement or nondisclosure
agreement with Intel Corporation and may not be copied or disclosed except in
accordance with the terms of that agreement
Copyright(c) 2012-2014 Intel Corporation. All Rights Reserved.
**********************************************************************************/
#include <new> // std::bad_alloc
#include "thread_defs.h"
AutomaticMutex::AutomaticMutex(MSDKMutex& mutex):
m_rMutex(mutex),
m_bLocked(false)
{
if (MFX_ERR_NONE != Lock()) throw std::bad_alloc();
};
AutomaticMutex::~AutomaticMutex(void)
{
Unlock();
}
mfxStatus AutomaticMutex::Lock(void)
{
mfxStatus sts = MFX_ERR_NONE;
if (!m_bLocked)
{
if (!m_rMutex.Try())
{
// add time measurement here to estimate how long you sleep on mutex...
sts = m_rMutex.Lock();
}
m_bLocked = true;
}
return sts;
}
mfxStatus AutomaticMutex::Unlock(void)
{
mfxStatus sts = MFX_ERR_NONE;
if (m_bLocked)
{
sts = m_rMutex.Unlock();
m_bLocked = false;
}
return sts;
}