summaryrefslogtreecommitdiff
path: root/noncore/multimedia/opieplayer2/threadutil.cpp
Unidiff
Diffstat (limited to 'noncore/multimedia/opieplayer2/threadutil.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/multimedia/opieplayer2/threadutil.cpp17
1 files changed, 11 insertions, 6 deletions
diff --git a/noncore/multimedia/opieplayer2/threadutil.cpp b/noncore/multimedia/opieplayer2/threadutil.cpp
index b5cac61..5fc8a0b 100644
--- a/noncore/multimedia/opieplayer2/threadutil.cpp
+++ b/noncore/multimedia/opieplayer2/threadutil.cpp
@@ -188,102 +188,107 @@ void Thread::start()
188 AutoLock lock( d->guard ); 188 AutoLock lock( d->guard );
189 189
190 if ( d->isRunning ) { 190 if ( d->isRunning ) {
191 odebug << "ThreadUtil::Thread::start() called for running thread." << oendl; 191 odebug << "ThreadUtil::Thread::start() called for running thread." << oendl;
192 return; 192 return;
193 } 193 }
194 194
195 pthread_attr_t attributes; 195 pthread_attr_t attributes;
196 pthread_attr_init( &attributes ); 196 pthread_attr_init( &attributes );
197 pthread_attr_setscope( &attributes, PTHREAD_SCOPE_SYSTEM ); 197 pthread_attr_setscope( &attributes, PTHREAD_SCOPE_SYSTEM );
198 int err = pthread_create( &d->self, &attributes, start_thread, ( void* )d ); 198 int err = pthread_create( &d->self, &attributes, start_thread, ( void* )d );
199 if ( err != 0 ) { 199 if ( err != 0 ) {
200 odebug << "ThreadUtil::Thread::start() : can't create thread: " << strerror( err ) << "" << oendl; 200 odebug << "ThreadUtil::Thread::start() : can't create thread: " << strerror( err ) << "" << oendl;
201 pthread_attr_destroy( &attributes ); 201 pthread_attr_destroy( &attributes );
202 return; 202 return;
203 } 203 }
204 pthread_attr_destroy( &attributes ); 204 pthread_attr_destroy( &attributes );
205} 205}
206 206
207void Thread::terminate() 207void Thread::terminate()
208{ 208{
209 AutoLock lock( d->guard ); 209 AutoLock lock( d->guard );
210 if ( !d->isRunning ) 210 if ( !d->isRunning )
211 return; 211 return;
212 212
213 pthread_cancel( d->self ); 213 pthread_cancel( d->self );
214} 214}
215 215
216bool Thread::wait() 216bool Thread::wait()
217{ 217{
218 AutoLock lock( d->guard ); 218 AutoLock lock( d->guard );
219 if ( !d->isRunning ) 219 if ( !d->isRunning )
220 return true; 220 return true;
221 221
222 return d->finishCondition.wait( d->guard ); 222 return d->finishCondition.wait( d->guard );
223} 223}
224 224
225bool Thread::isRunning() const 225bool Thread::isRunning() const
226{ 226{
227 AutoLock lock( d->guard ); 227 AutoLock lock( d->guard );
228 return d->isRunning; 228 return d->isRunning;
229} 229}
230 230
231void Thread::exit() 231void Thread::exit()
232{ 232{
233 pthread_exit( 0 ); 233 pthread_exit( 0 );
234} 234}
235 235
236OnewayNotifier::OnewayNotifier() 236OnewayNotifier::OnewayNotifier() :
237{ 237 m_readFd(-1),
238 int fds[ 2 ]; 238 m_writeFd(-1)
239 pipe( fds ); 239{
240 m_readFd = fds[ 0 ]; 240 int fds[ 2 ] = { -1, -1 };
241 m_writeFd = fds[ 1 ]; 241 if (pipe( fds ) == 0) {
242 m_readFd = fds[ 0 ];
243 m_writeFd = fds[ 1 ];
244 } else {
245 owarn << "Call to pipe() failed" << oendl;
246 }
242 247
243 m_notifier = new QSocketNotifier( m_readFd, QSocketNotifier::Read ); 248 m_notifier = new QSocketNotifier( m_readFd, QSocketNotifier::Read );
244 connect( m_notifier, SIGNAL( activated(int) ), 249 connect( m_notifier, SIGNAL( activated(int) ),
245 this, SLOT( wakeUp() ) ); 250 this, SLOT( wakeUp() ) );
246} 251}
247 252
248OnewayNotifier::~OnewayNotifier() 253OnewayNotifier::~OnewayNotifier()
249{ 254{
250 delete m_notifier; 255 delete m_notifier;
251 256
252 ::close( m_readFd ); 257 ::close( m_readFd );
253 ::close( m_writeFd ); 258 ::close( m_writeFd );
254} 259}
255 260
256void OnewayNotifier::notify() 261void OnewayNotifier::notify()
257{ 262{
258 const char c = 42; 263 const char c = 42;
259 ::write( m_writeFd, &c, 1 ); 264 ::write( m_writeFd, &c, 1 );
260} 265}
261 266
262void OnewayNotifier::wakeUp() 267void OnewayNotifier::wakeUp()
263{ 268{
264 char c = 0; 269 char c = 0;
265 270
266 if ( ::read( m_readFd, &c, 1 ) != 1 ) 271 if ( ::read( m_readFd, &c, 1 ) != 1 )
267 return; 272 return;
268 273
269 emit awake(); 274 emit awake();
270} 275}
271 276
272ChannelMessage::ChannelMessage( int type, int data, const char* msg ) 277ChannelMessage::ChannelMessage( int type, int data, const char* msg )
273 : m_type( type ), m_data( data ), m_msg( msg ), 278 : m_type( type ), m_data( data ), m_msg( msg ),
274 m_isCall( false ), m_replied( false ), m_inEventHandler( false ) 279 m_isCall( false ), m_replied( false ), m_inEventHandler( false )
275{} 280{}
276 281
277ChannelMessage::~ChannelMessage() 282ChannelMessage::~ChannelMessage()
278{ 283{
279 if ( m_guard.isLocked() ) 284 if ( m_guard.isLocked() )
280 m_guard.unlock(); 285 m_guard.unlock();
281} 286}
282 287
283void ChannelMessage::reply() 288void ChannelMessage::reply()
284{ 289{
285 if ( !m_isCall ) 290 if ( !m_isCall )
286 { 291 {
287 odebug << "ChannelMessage::reply() - can't reply oneway message!" << oendl; 292 odebug << "ChannelMessage::reply() - can't reply oneway message!" << oendl;
288 return; 293 return;
289 } 294 }