summaryrefslogtreecommitdiff
path: root/noncore/multimedia
authorsimon <simon>2002-12-11 11:05:52 (UTC)
committer simon <simon>2002-12-11 11:05:52 (UTC)
commitdd7fcdf1589c8513055f6475d3a1f33075d971d8 (patch) (unidiff)
tree3b4927a023eea68d1c529b4852ce2cdd1801db49 /noncore/multimedia
parent616e7437498c7adcad77d9b79e9c450a75b260ca (diff)
downloadopie-dd7fcdf1589c8513055f6475d3a1f33075d971d8.zip
opie-dd7fcdf1589c8513055f6475d3a1f33075d971d8.tar.gz
opie-dd7fcdf1589c8513055f6475d3a1f33075d971d8.tar.bz2
- gcc2 is not my friend, given that it can't deal with friend declarations
properly :) (a.k.a: make it compile with gcc2, step 2)
Diffstat (limited to 'noncore/multimedia') (more/less context) (show whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/threadutil.cpp17
-rw-r--r--noncore/multimedia/opieplayer2/threadutil.h6
2 files changed, 11 insertions, 12 deletions
diff --git a/noncore/multimedia/opieplayer2/threadutil.cpp b/noncore/multimedia/opieplayer2/threadutil.cpp
index 7a9e1a4..ff38b1e 100644
--- a/noncore/multimedia/opieplayer2/threadutil.cpp
+++ b/noncore/multimedia/opieplayer2/threadutil.cpp
@@ -124,81 +124,86 @@ void WaitCondition::wakeAll()
124} 124}
125 125
126struct Thread::Data 126struct Thread::Data
127{ 127{
128 Data() : isRunning( false ) 128 Data() : isRunning( false )
129 {} 129 {}
130 130
131 pthread_t self; 131 pthread_t self;
132 Mutex guard; 132 Mutex guard;
133 bool isRunning; 133 bool isRunning;
134 134
135 WaitCondition finishCondition; 135 WaitCondition finishCondition;
136
137 Thread *thr;
138
139 void run() { thr->run(); }
136}; 140};
137 141
138extern "C" 142extern "C"
139{ 143{
140 144
141static void terminate_thread( void *arg ) 145static void terminate_thread( void *arg )
142{ 146{
143 Thread::Data *data = ( Thread::Data* )arg; 147 Thread::Data *data = ( Thread::Data* )arg;
144 148
145 assert( data ); 149 assert( data );
146 150
147 AutoLock locker( data->guard ); 151 AutoLock locker( data->guard );
148 data->isRunning = false; 152 data->isRunning = false;
149 data->finishCondition.wakeAll(); 153 data->finishCondition.wakeAll();
150} 154}
151 155
152void *_threadutil_start_thread( void *arg ) 156static void *start_thread( void *arg )
153{ 157{
154 Thread *thr = ( Thread* )arg; 158 Thread::Data *data = ( Thread::Data* )arg;
155 159
156 pthread_cleanup_push( terminate_thread, thr->d ); 160 pthread_cleanup_push( terminate_thread, data );
157 161
158 thr->d->isRunning = true; 162 data->isRunning = true;
159 thr->run(); 163 data->run();
160 164
161 pthread_cleanup_pop( true ); 165 pthread_cleanup_pop( true );
162 166
163 Thread::exit(); 167 Thread::exit();
164 return 0; // never reached 168 return 0; // never reached
165} 169}
166 170
167} 171}
168 172
169Thread::Thread() 173Thread::Thread()
170 : d( new Data ) 174 : d( new Data )
171{ 175{
176 d->thr = this;
172} 177}
173 178
174Thread::~Thread() 179Thread::~Thread()
175{ 180{
176 assert( d->isRunning == false ); 181 assert( d->isRunning == false );
177 delete d; 182 delete d;
178} 183}
179 184
180void Thread::start() 185void Thread::start()
181{ 186{
182 AutoLock lock( d->guard ); 187 AutoLock lock( d->guard );
183 188
184 if ( d->isRunning ) { 189 if ( d->isRunning ) {
185 qDebug( "ThreadUtil::Thread::start() called for running thread." ); 190 qDebug( "ThreadUtil::Thread::start() called for running thread." );
186 return; 191 return;
187 } 192 }
188 193
189 pthread_attr_t attributes; 194 pthread_attr_t attributes;
190 pthread_attr_init( &attributes ); 195 pthread_attr_init( &attributes );
191 pthread_attr_setscope( &attributes, PTHREAD_SCOPE_SYSTEM ); 196 pthread_attr_setscope( &attributes, PTHREAD_SCOPE_SYSTEM );
192 int err = pthread_create( &d->self, &attributes, _threadutil_start_thread, ( void* )this ); 197 int err = pthread_create( &d->self, &attributes, start_thread, ( void* )d );
193 if ( err != 0 ) { 198 if ( err != 0 ) {
194 qDebug( "ThreadUtil::Thread::start() : can't create thread: %s", strerror( err ) ); 199 qDebug( "ThreadUtil::Thread::start() : can't create thread: %s", strerror( err ) );
195 pthread_attr_destroy( &attributes ); 200 pthread_attr_destroy( &attributes );
196 return; 201 return;
197 } 202 }
198 pthread_attr_destroy( &attributes ); 203 pthread_attr_destroy( &attributes );
199} 204}
200 205
201void Thread::terminate() 206void Thread::terminate()
202{ 207{
203 AutoLock lock( d->guard ); 208 AutoLock lock( d->guard );
204 if ( !d->isRunning ) 209 if ( !d->isRunning )
diff --git a/noncore/multimedia/opieplayer2/threadutil.h b/noncore/multimedia/opieplayer2/threadutil.h
index 21ae6b2..2fd0c68 100644
--- a/noncore/multimedia/opieplayer2/threadutil.h
+++ b/noncore/multimedia/opieplayer2/threadutil.h
@@ -17,29 +17,24 @@
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
29extern "C"
30{
31 void *_threadutil_start_thread( void* );
32}
33
34namespace ThreadUtil 29namespace ThreadUtil
35{ 30{
36 31
37 class Mutex 32 class Mutex
38 { 33 {
39 friend class WaitCondition; 34 friend class WaitCondition;
40 public: 35 public:
41 Mutex(); 36 Mutex();
42 ~Mutex(); 37 ~Mutex();
43 38
44 void lock(); 39 void lock();
45 void unlock(); 40 void unlock();
@@ -79,25 +74,24 @@ namespace ThreadUtil
79 void wakeAll(); 74 void wakeAll();
80 75
81 private: 76 private:
82 struct Data; 77 struct Data;
83 Data *d; 78 Data *d;
84 79
85 WaitCondition( const WaitCondition & ); 80 WaitCondition( const WaitCondition & );
86 WaitCondition &operator=( const WaitCondition & ); 81 WaitCondition &operator=( const WaitCondition & );
87 }; 82 };
88 83
89 class Thread 84 class Thread
90 { 85 {
91 friend void *::_threadutil_start_thread( void* );
92 public: 86 public:
93 struct Data; 87 struct Data;
94 88
95 Thread(); 89 Thread();
96 virtual ~Thread(); 90 virtual ~Thread();
97 91
98 void start(); 92 void start();
99 void terminate(); 93 void terminate();
100 94
101 bool wait(); 95 bool wait();
102 96
103 bool isRunning() const; 97 bool isRunning() const;