3 * Copyright (c) 2002 Frodo
4 * Portions Copyright (c) by the authors of ffmpeg and xvid
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "SingleLock.h"
24 //////////////////////////////////////////////////////////////////////
25 // Construction/Destruction
26 //////////////////////////////////////////////////////////////////////
28 CSingleLock::CSingleLock(CCriticalSection
& cs
)
35 CSingleLock::CSingleLock(const CCriticalSection
& cs
)
36 : m_cs( const_cast<CCriticalSection
&>(cs
) )
42 CSingleLock::~CSingleLock()
47 bool CSingleLock::IsOwner() const
52 bool CSingleLock::Enter()
54 // Test if we already own the critical section
55 if ( true == m_bIsOwner
)
61 ::EnterCriticalSection( m_cs
);
67 void CSingleLock::Leave()
69 if ( false == m_bIsOwner
)
74 ::LeaveCriticalSection( m_cs
);
78 CSingleExit::CSingleExit(CCriticalSection
& cs
)
85 CSingleExit::CSingleExit(const CCriticalSection
& cs
)
86 : m_cs(const_cast<CCriticalSection
&>(cs
))
92 CSingleExit::~CSingleExit()
97 void CSingleExit::Exit()
100 m_count
= ::ExitCriticalSection(m_cs
);
103 void CSingleExit::Restore()
107 RestoreCriticalSection(m_cs
, m_count
);