summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/threadutil.h1
1 files changed, 1 insertions, 0 deletions
diff --git a/noncore/multimedia/opieplayer2/threadutil.h b/noncore/multimedia/opieplayer2/threadutil.h
index 2fd0c68..1411535 100644
--- a/noncore/multimedia/opieplayer2/threadutil.h
+++ b/noncore/multimedia/opieplayer2/threadutil.h
@@ -1,199 +1,200 @@
1/* This file is part of the KDE project 1/* This file is part of the KDE project
2 Copyright (C) 2002 Simon Hausmann <hausmann@kde.org> 2 Copyright (C) 2002 Simon Hausmann <hausmann@kde.org>
3 3
4 This library is free software; you can redistribute it and/or 4 This library is free software; you can redistribute it and/or
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
27class QSocketNotifier; 27class QSocketNotifier;
28 28
29namespace ThreadUtil 29namespace ThreadUtil
30{ 30{
31 31
32 class Mutex 32 class Mutex
33 { 33 {
34 friend class WaitCondition; 34 friend class WaitCondition;
35 public: 35 public:
36 Mutex(); 36 Mutex();
37 ~Mutex(); 37 ~Mutex();
38 38
39 void lock(); 39 void lock();
40 void unlock(); 40 void unlock();
41 bool tryLock(); 41 bool tryLock();
42 bool isLocked(); 42 bool isLocked();
43 43
44 private: 44 private:
45 struct Data; 45 struct Data;
46 Data *d; 46 Data *d;
47 47
48 Mutex( const Mutex & ); 48 Mutex( const Mutex & );
49 Mutex &operator=( const Mutex & ); 49 Mutex &operator=( const Mutex & );
50 }; 50 };
51 51
52 class AutoLock 52 class AutoLock
53 { 53 {
54 public: 54 public:
55 AutoLock( Mutex &mutex ) : m_mutex( mutex ) { m_mutex.lock(); } 55 AutoLock( Mutex &mutex ) : m_mutex( mutex ) { m_mutex.lock(); }
56 ~AutoLock() { m_mutex.unlock(); } 56 ~AutoLock() { m_mutex.unlock(); }
57 57
58 Mutex *operator &() const { return &m_mutex; } 58 Mutex *operator &() const { return &m_mutex; }
59 59
60 private: 60 private:
61 Mutex &m_mutex; 61 Mutex &m_mutex;
62 }; 62 };
63 63
64 class WaitCondition 64 class WaitCondition
65 { 65 {
66 public: 66 public:
67 WaitCondition(); 67 WaitCondition();
68 ~WaitCondition(); 68 ~WaitCondition();
69 69
70 bool wait(); 70 bool wait();
71 bool wait( Mutex &mutex ); 71 bool wait( Mutex &mutex );
72 72
73 void wakeOne(); 73 void wakeOne();
74 void wakeAll(); 74 void wakeAll();
75 75
76 private: 76 private:
77 struct Data; 77 struct Data;
78 Data *d; 78 Data *d;
79 79
80 WaitCondition( const WaitCondition & ); 80 WaitCondition( const WaitCondition & );
81 WaitCondition &operator=( const WaitCondition & ); 81 WaitCondition &operator=( const WaitCondition & );
82 }; 82 };
83 83
84 class Thread 84 class Thread
85 { 85 {
86 public: 86 public:
87 struct Data; 87 struct Data;
88 friend struct Data;
88 89
89 Thread(); 90 Thread();
90 virtual ~Thread(); 91 virtual ~Thread();
91 92
92 void start(); 93 void start();
93 void terminate(); 94 void terminate();
94 95
95 bool wait(); 96 bool wait();
96 97
97 bool isRunning() const; 98 bool isRunning() const;
98 99
99 static void exit(); 100 static void exit();
100 protected: 101 protected:
101 virtual void run() = 0; 102 virtual void run() = 0;
102 103
103 private: 104 private:
104 Data *d; 105 Data *d;
105 }; 106 };
106 107
107 class OnewayNotifier : public QObject 108 class OnewayNotifier : public QObject
108 { 109 {
109 Q_OBJECT 110 Q_OBJECT
110 public: 111 public:
111 OnewayNotifier(); 112 OnewayNotifier();
112 ~OnewayNotifier(); 113 ~OnewayNotifier();
113 114
114 void notify(); 115 void notify();
115 116
116 signals: 117 signals:
117 void awake(); 118 void awake();
118 119
119 private slots: 120 private slots:
120 void wakeUp(); 121 void wakeUp();
121 122
122 private: 123 private:
123 int m_readFd; 124 int m_readFd;
124 int m_writeFd; 125 int m_writeFd;
125 QSocketNotifier *m_notifier; 126 QSocketNotifier *m_notifier;
126 }; 127 };
127 128
128 129
129 class Channel; 130 class Channel;
130 131
131 class ChannelMessage 132 class ChannelMessage
132 { 133 {
133 friend class Channel; 134 friend class Channel;
134 public: 135 public:
135 ChannelMessage( int type = -1 ); 136 ChannelMessage( int type = -1 );
136 virtual ~ChannelMessage(); 137 virtual ~ChannelMessage();
137 138
138 int type() const { return m_type; } 139 int type() const { return m_type; }
139 140
140 void reply(); 141 void reply();
141 142
142 private: 143 private:
143 ChannelMessage( const ChannelMessage & ); 144 ChannelMessage( const ChannelMessage & );
144 ChannelMessage &operator=( const ChannelMessage ); 145 ChannelMessage &operator=( const ChannelMessage );
145 146
146 int m_type; 147 int m_type;
147 bool m_isCall : 1; 148 bool m_isCall : 1;
148 bool m_replied : 1; 149 bool m_replied : 1;
149 bool m_inEventHandler : 1; 150 bool m_inEventHandler : 1;
150 Mutex m_guard; 151 Mutex m_guard;
151 WaitCondition m_condition; 152 WaitCondition m_condition;
152 QGuardedPtr<Channel> m_channel; 153 QGuardedPtr<Channel> m_channel;
153 }; 154 };
154 155
155 class Channel : public QObject 156 class Channel : public QObject
156 { 157 {
157 Q_OBJECT 158 Q_OBJECT
158 public: 159 public:
159 enum SendType { OneWay, WaitForReply }; 160 enum SendType { OneWay, WaitForReply };
160 Channel( QObject *parent = 0, const char *name = 0 ); 161 Channel( QObject *parent = 0, const char *name = 0 );
161 virtual ~Channel(); 162 virtual ~Channel();
162 163
163 void send( ChannelMessage *message, SendType type ); 164 void send( ChannelMessage *message, SendType type );
164 165
165 protected: 166 protected:
166 virtual void receiveMessage( ChannelMessage *message, SendType type ) = 0; 167 virtual void receiveMessage( ChannelMessage *message, SendType type ) = 0;
167 168
168 private slots: 169 private slots:
169 void deliver(); 170 void deliver();
170 171
171 private: 172 private:
172 OnewayNotifier m_notifier; 173 OnewayNotifier m_notifier;
173 174
174 struct MsgEnvelope 175 struct MsgEnvelope
175 { 176 {
176 MsgEnvelope() : type( OneWay ), msg( 0 ) {} 177 MsgEnvelope() : type( OneWay ), msg( 0 ) {}
177 MsgEnvelope( SendType _type , ChannelMessage *_msg ) 178 MsgEnvelope( SendType _type , ChannelMessage *_msg )
178 : type( _type ), msg( _msg ) {} 179 : type( _type ), msg( _msg ) {}
179 180
180 SendType type; 181 SendType type;
181 ChannelMessage *msg; 182 ChannelMessage *msg;
182 }; 183 };
183 184
184 void deliverOne( const MsgEnvelope &envelope ); 185 void deliverOne( const MsgEnvelope &envelope );
185 186
186 typedef QValueList<MsgEnvelope> MsgEnvelopeList; 187 typedef QValueList<MsgEnvelope> MsgEnvelopeList;
187 188
188 MsgEnvelopeList m_pendingMessages; 189 MsgEnvelopeList m_pendingMessages;
189 Mutex m_pendingMessagesGuard; 190 Mutex m_pendingMessagesGuard;
190 191
191 struct Private; 192 struct Private;
192 Private *d; 193 Private *d;
193 }; 194 };
194 195
195} 196}
196 197
197#endif // THREADUTIL_H 198#endif // THREADUTIL_H
198/* vim: et sw=4 ts=4 199/* vim: et sw=4 ts=4
199 */ 200 */