summaryrefslogtreecommitdiff
path: root/noncore/multimedia/opieplayer2/threadutil.cpp
Side-by-side diff
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()
AutoLock lock( d->guard );
if ( d->isRunning ) {
odebug << "ThreadUtil::Thread::start() called for running thread." << oendl;
return;
}
pthread_attr_t attributes;
pthread_attr_init( &attributes );
pthread_attr_setscope( &attributes, PTHREAD_SCOPE_SYSTEM );
int err = pthread_create( &d->self, &attributes, start_thread, ( void* )d );
if ( err != 0 ) {
odebug << "ThreadUtil::Thread::start() : can't create thread: " << strerror( err ) << "" << oendl;
pthread_attr_destroy( &attributes );
return;
}
pthread_attr_destroy( &attributes );
}
void Thread::terminate()
{
AutoLock lock( d->guard );
if ( !d->isRunning )
return;
pthread_cancel( d->self );
}
bool Thread::wait()
{
AutoLock lock( d->guard );
if ( !d->isRunning )
return true;
return d->finishCondition.wait( d->guard );
}
bool Thread::isRunning() const
{
AutoLock lock( d->guard );
return d->isRunning;
}
void Thread::exit()
{
pthread_exit( 0 );
}
-OnewayNotifier::OnewayNotifier()
-{
- int fds[ 2 ];
- pipe( fds );
- m_readFd = fds[ 0 ];
- m_writeFd = fds[ 1 ];
+OnewayNotifier::OnewayNotifier() :
+ m_readFd(-1),
+ m_writeFd(-1)
+{
+ int fds[ 2 ] = { -1, -1 };
+ if (pipe( fds ) == 0) {
+ m_readFd = fds[ 0 ];
+ m_writeFd = fds[ 1 ];
+ } else {
+ owarn << "Call to pipe() failed" << oendl;
+ }
m_notifier = new QSocketNotifier( m_readFd, QSocketNotifier::Read );
connect( m_notifier, SIGNAL( activated(int) ),
this, SLOT( wakeUp() ) );
}
OnewayNotifier::~OnewayNotifier()
{
delete m_notifier;
::close( m_readFd );
::close( m_writeFd );
}
void OnewayNotifier::notify()
{
const char c = 42;
::write( m_writeFd, &c, 1 );
}
void OnewayNotifier::wakeUp()
{
char c = 0;
if ( ::read( m_readFd, &c, 1 ) != 1 )
return;
emit awake();
}
ChannelMessage::ChannelMessage( int type, int data, const char* msg )
: m_type( type ), m_data( data ), m_msg( msg ),
m_isCall( false ), m_replied( false ), m_inEventHandler( false )
{}
ChannelMessage::~ChannelMessage()
{
if ( m_guard.isLocked() )
m_guard.unlock();
}
void ChannelMessage::reply()
{
if ( !m_isCall )
{
odebug << "ChannelMessage::reply() - can't reply oneway message!" << oendl;
return;
}