Diffstat (limited to 'noncore/multimedia/opieplayer2/threadutil.h') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/multimedia/opieplayer2/threadutil.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/noncore/multimedia/opieplayer2/threadutil.h b/noncore/multimedia/opieplayer2/threadutil.h index 5cc4cdc..b537cc1 100644 --- a/noncore/multimedia/opieplayer2/threadutil.h +++ b/noncore/multimedia/opieplayer2/threadutil.h | |||
@@ -5,48 +5,54 @@ | |||
5 | modify it under the terms of the GNU Library General Public | 5 | modify it under the terms of the GNU Library General Public |
6 | License as published by the Free Software Foundation; either | 6 | License as published by the Free Software Foundation; either |
7 | version 2 of the License, or (at your option) any later version. | 7 | version 2 of the License, or (at your option) any later version. |
8 | 8 | ||
9 | This library is distributed in the hope that it will be useful, | 9 | This library is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | Library General Public License for more details. | 12 | Library General Public License for more details. |
13 | 13 | ||
14 | You should have received a copy of the GNU Library General Public License | 14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to | 15 | along with this library; see the file COPYING.LIB. If not, write to |
16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | 16 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
17 | Boston, MA 02111-1307, USA. | 17 | Boston, MA 02111-1307, USA. |
18 | */ | 18 | */ |
19 | 19 | ||
20 | #ifndef THREADUTIL_H | 20 | #ifndef THREADUTIL_H |
21 | #define THREADUTIL_H | 21 | #define THREADUTIL_H |
22 | 22 | ||
23 | #include <qvaluelist.h> | 23 | #include <qvaluelist.h> |
24 | #include <qobject.h> | 24 | #include <qobject.h> |
25 | #include <qguardedptr.h> | 25 | #include <qguardedptr.h> |
26 | 26 | ||
27 | class QSocketNotifier; | 27 | class QSocketNotifier; |
28 | 28 | ||
29 | extern "C" | ||
30 | { | ||
31 | void *_threadutil_start_thread( void* ); | ||
32 | void _threadutil_terminate_thread( void* ); | ||
33 | } | ||
34 | |||
29 | namespace ThreadUtil | 35 | namespace ThreadUtil |
30 | { | 36 | { |
31 | 37 | ||
32 | class Mutex | 38 | class Mutex |
33 | { | 39 | { |
34 | friend class WaitCondition; | 40 | friend class WaitCondition; |
35 | public: | 41 | public: |
36 | Mutex(); | 42 | Mutex(); |
37 | ~Mutex(); | 43 | ~Mutex(); |
38 | 44 | ||
39 | void lock(); | 45 | void lock(); |
40 | void unlock(); | 46 | void unlock(); |
41 | bool tryLock(); | 47 | bool tryLock(); |
42 | bool isLocked(); | 48 | bool isLocked(); |
43 | 49 | ||
44 | private: | 50 | private: |
45 | struct Data; | 51 | struct Data; |
46 | Data *d; | 52 | Data *d; |
47 | 53 | ||
48 | Mutex( const Mutex & ); | 54 | Mutex( const Mutex & ); |
49 | Mutex &operator=( const Mutex & ); | 55 | Mutex &operator=( const Mutex & ); |
50 | }; | 56 | }; |
51 | 57 | ||
52 | class AutoLock | 58 | class AutoLock |
@@ -60,48 +66,70 @@ namespace ThreadUtil | |||
60 | private: | 66 | private: |
61 | Mutex &m_mutex; | 67 | Mutex &m_mutex; |
62 | }; | 68 | }; |
63 | 69 | ||
64 | class WaitCondition | 70 | class WaitCondition |
65 | { | 71 | { |
66 | public: | 72 | public: |
67 | WaitCondition(); | 73 | WaitCondition(); |
68 | ~WaitCondition(); | 74 | ~WaitCondition(); |
69 | 75 | ||
70 | bool wait(); | 76 | bool wait(); |
71 | bool wait( Mutex &mutex ); | 77 | bool wait( Mutex &mutex ); |
72 | 78 | ||
73 | void wakeOne(); | 79 | void wakeOne(); |
74 | void wakeAll(); | 80 | void wakeAll(); |
75 | 81 | ||
76 | private: | 82 | private: |
77 | struct Data; | 83 | struct Data; |
78 | Data *d; | 84 | Data *d; |
79 | 85 | ||
80 | WaitCondition( const WaitCondition & ); | 86 | WaitCondition( const WaitCondition & ); |
81 | WaitCondition &operator=( const WaitCondition & ); | 87 | WaitCondition &operator=( const WaitCondition & ); |
82 | }; | 88 | }; |
83 | 89 | ||
90 | class Thread | ||
91 | { | ||
92 | friend void *::_threadutil_start_thread( void* ); | ||
93 | friend void ::_threadutil_terminate_thread( void* ); | ||
94 | public: | ||
95 | Thread(); | ||
96 | virtual ~Thread(); | ||
97 | |||
98 | void start(); | ||
99 | void terminate(); | ||
100 | |||
101 | bool wait(); | ||
102 | |||
103 | static void exit(); | ||
104 | protected: | ||
105 | virtual void run() = 0; | ||
106 | |||
107 | private: | ||
108 | struct Data; | ||
109 | Data *d; | ||
110 | }; | ||
111 | |||
84 | class OnewayNotifier : public QObject | 112 | class OnewayNotifier : public QObject |
85 | { | 113 | { |
86 | Q_OBJECT | 114 | Q_OBJECT |
87 | public: | 115 | public: |
88 | OnewayNotifier(); | 116 | OnewayNotifier(); |
89 | ~OnewayNotifier(); | 117 | ~OnewayNotifier(); |
90 | 118 | ||
91 | void notify(); | 119 | void notify(); |
92 | 120 | ||
93 | signals: | 121 | signals: |
94 | void awake(); | 122 | void awake(); |
95 | 123 | ||
96 | private slots: | 124 | private slots: |
97 | void wakeUp(); | 125 | void wakeUp(); |
98 | 126 | ||
99 | private: | 127 | private: |
100 | int m_readFd; | 128 | int m_readFd; |
101 | int m_writeFd; | 129 | int m_writeFd; |
102 | QSocketNotifier *m_notifier; | 130 | QSocketNotifier *m_notifier; |
103 | }; | 131 | }; |
104 | 132 | ||
105 | 133 | ||
106 | class Channel; | 134 | class Channel; |
107 | 135 | ||