Commit | Line | Data |
---|---|---|
abbca718 LOK |
1 | #pragma once |
2 | /* | |
3 | * This file is part of the libCEC(R) library. | |
4 | * | |
5 | * libCEC(R) is Copyright (C) 2011 Pulse-Eight Limited. All rights reserved. | |
6 | * libCEC(R) is an original work, containing original code. | |
7 | * | |
8 | * libCEC(R) is a trademark of Pulse-Eight Limited. | |
9 | * | |
10 | * This program is dual-licensed; you can redistribute it and/or modify | |
11 | * it under the terms of the GNU General Public License as published by | |
12 | * the Free Software Foundation; either version 2 of the License, or | |
13 | * (at your option) any later version. | |
14 | * | |
15 | * This program is distributed in the hope that it will be useful, | |
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 | * GNU General Public License for more details. | |
19 | * | |
20 | * You should have received a copy of the GNU General Public License | |
21 | * along with this program; if not, write to the Free Software | |
22 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | |
23 | * | |
24 | * | |
25 | * Alternatively, you can license this library under a commercial license, | |
26 | * please contact Pulse-Eight Licensing for more information. | |
27 | * | |
28 | * For more information contact: | |
29 | * Pulse-Eight Licensing <license@pulse-eight.com> | |
30 | * http://www.pulse-eight.com/ | |
31 | * http://www.pulse-eight.net/ | |
32 | */ | |
33 | ||
5559c36e | 34 | #include <stdint.h> |
abbca718 | 35 | |
b9187cc6 | 36 | namespace CEC |
abbca718 | 37 | { |
6f14b512 LOK |
38 | class IMutex |
39 | { | |
40 | public: | |
41 | IMutex(bool bRecursive = true) { m_bRecursive = bRecursive ; }; | |
42 | virtual ~IMutex(void) {}; | |
43 | ||
44 | virtual bool TryLock(void) = 0; | |
45 | virtual bool Lock(void) = 0; | |
46 | virtual void Unlock(void) = 0; | |
47 | ||
48 | protected: | |
49 | bool m_bRecursive; | |
50 | }; | |
abbca718 | 51 | |
6f14b512 | 52 | class ICondition |
b9187cc6 LOK |
53 | { |
54 | public: | |
6f14b512 LOK |
55 | virtual void Broadcast(void) = 0; |
56 | virtual void Signal(void) = 0; | |
57 | virtual bool Wait(IMutex *mutex, uint32_t iTimeout = 0) = 0; | |
abbca718 | 58 | |
25701fa6 | 59 | static void Sleep(uint32_t iTimeout); |
b9187cc6 | 60 | }; |
abbca718 | 61 | |
6f14b512 | 62 | class IThread |
b9187cc6 LOK |
63 | { |
64 | public: | |
6f14b512 LOK |
65 | IThread(void); |
66 | virtual ~IThread(void); | |
abbca718 | 67 | |
6f14b512 LOK |
68 | virtual bool IsRunning(void) const { return m_bRunning; }; |
69 | virtual bool CreateThread(bool bWait = true) = 0; | |
70 | virtual bool IsStopped(void) const { return m_bStop; }; | |
abbca718 | 71 | |
6f14b512 LOK |
72 | virtual bool StopThread(bool bWaitForExit = true); |
73 | virtual bool Sleep(uint32_t iTimeout); | |
3154de8d | 74 | |
6f14b512 LOK |
75 | virtual void *Process(void) = 0; |
76 | ||
77 | protected: | |
78 | bool m_bStop; | |
79 | bool m_bRunning; | |
80 | ICondition *m_threadCondition; | |
81 | IMutex *m_threadMutex; | |
b9187cc6 | 82 | }; |
abbca718 | 83 | |
b9187cc6 LOK |
84 | class CLockObject |
85 | { | |
86 | public: | |
6f14b512 | 87 | CLockObject(IMutex *mutex, bool bTryLock = false); |
b9187cc6 | 88 | ~CLockObject(void); |
abbca718 | 89 | |
b9187cc6 LOK |
90 | bool IsLocked(void) const { return m_bLocked; } |
91 | void Leave(void); | |
92 | void Lock(void); | |
60fa4578 | 93 | |
b9187cc6 | 94 | private: |
6f14b512 | 95 | IMutex *m_mutex; |
b9187cc6 LOK |
96 | bool m_bLocked; |
97 | }; | |
60fa4578 | 98 | }; |