diff --git a/include/RemotePlugin.h b/include/RemotePlugin.h index aeba87601..1292150e1 100644 --- a/include/RemotePlugin.h +++ b/include/RemotePlugin.h @@ -36,6 +36,7 @@ #include #ifdef LMMS_BUILD_WIN32 +#include #define USE_QT_SEMAPHORES #define USE_QT_SHMEM #endif @@ -284,7 +285,7 @@ public: // recursive lock inline void lock() { - if( !isInvalid() && ++m_lockDepth == 1 ) + if( likely( !isInvalid() && ++m_lockDepth == 1 ) ) { #ifdef USE_QT_SEMAPHORES m_dataSem.acquire(); @@ -297,9 +298,9 @@ public: // recursive unlock inline void unlock() { - if( m_lockDepth > 0 ) + if( likely( m_lockDepth > 0 ) ) { - if( --m_lockDepth == 0 ) + if( likely( --m_lockDepth == 0 ) ) { #ifdef USE_QT_SEMAPHORES m_dataSem.release(); @@ -313,7 +314,7 @@ public: // wait until message-semaphore is available inline void waitForMessage() { - if( !isInvalid() ) + if( likely( !isInvalid() ) ) { #ifdef USE_QT_SEMAPHORES m_messageSem.acquire(); @@ -372,7 +373,7 @@ public: inline bool messagesLeft() { - if( isInvalid() ) + if( unlikely( isInvalid() ) ) { return false; } @@ -547,7 +548,7 @@ public: message & addInt( int _i ) { - char buf[128]; + char buf[64]; buf[0] = 0; sprintf( buf, "%d", _i ); data.push_back( std::string( buf ) ); @@ -556,7 +557,7 @@ public: message & addFloat( float _f ) { - char buf[128]; + char buf[64]; buf[0] = 0; sprintf( buf, "%f", _f ); data.push_back( std::string( buf ) ); @@ -617,16 +618,16 @@ public: message waitForMessage( const message & _m, - bool _busy_waiting = false ); + bool _busyWaiting = false ); - inline message fetchAndProcessNextMessage() + message fetchAndProcessNextMessage() { message m = receiveMessage(); processMessage( m ); return m; } - inline void fetchAndProcessAllMessages() + void fetchAndProcessAllMessages() { while( messagesLeft() ) { @@ -708,10 +709,9 @@ public: #endif } - inline void waitForInitDone( bool _busy_waiting = true ) + inline void waitForInitDone( bool _busyWaiting = true ) { - m_failed = waitForMessage( IdInitDone, - _busy_waiting ).id != IdInitDone; + m_failed = waitForMessage( IdInitDone, _busyWaiting ).id != IdInitDone; } virtual bool processMessage( const message & _m ); @@ -748,7 +748,7 @@ public: inline void lock() { - if( !isInvalid() ) + if( likely( !isInvalid() ) ) { m_commMutex.lock(); } @@ -756,7 +756,7 @@ public: inline void unlock() { - if( !isInvalid() ) + if( likely( !isInvalid() ) ) { m_commMutex.unlock(); } @@ -923,14 +923,13 @@ RemotePluginBase::~RemotePluginBase() void RemotePluginBase::sendMessage( const message & _m ) { + const int n = _m.data.size(); m_out->lock(); m_out->writeInt( _m.id ); - m_out->writeInt( _m.data.size() ); - int j = 0; - for( unsigned int i = 0; i < _m.data.size(); ++i ) + m_out->writeInt( n ); + for( unsigned int i = 0; i < n; ++i ) { m_out->writeString( _m.data[i] ); - j += _m.data[i].size(); } m_out->unlock(); m_out->messageSent(); @@ -968,6 +967,11 @@ RemotePluginBase::message RemotePluginBase::waitForMessage( { QCoreApplication::processEvents( QEventLoop::ExcludeUserInputEvents, 50 ); +#ifdef LMMS_BUILD_WIN32 + Sleep( 5 ); +#else + usleep( 5 * 1000 ); +#endif continue; } #endif @@ -1028,7 +1032,7 @@ RemotePluginClient::~RemotePluginClient() bool RemotePluginClient::processMessage( const message & _m ) { - message reply_message( _m.id ); + message replyMessage( _m.id ); bool reply = false; switch( _m.id ) { @@ -1060,7 +1064,7 @@ bool RemotePluginClient::processMessage( const message & _m ) case IdStartProcessing: doProcessing(); - reply_message.id = IdProcessingDone; + replyMessage.id = IdProcessingDone; reply = true; break; @@ -1081,7 +1085,7 @@ bool RemotePluginClient::processMessage( const message & _m ) } if( reply ) { - sendMessage( reply_message ); + sendMessage( replyMessage ); } return true; diff --git a/src/core/RemotePlugin.cpp b/src/core/RemotePlugin.cpp index a711d27cd..b60e386c8 100644 --- a/src/core/RemotePlugin.cpp +++ b/src/core/RemotePlugin.cpp @@ -150,7 +150,7 @@ bool RemotePlugin::process( const sampleFrame * _in_buf, { const fpp_t frames = engine::getMixer()->framesPerPeriod(); - if( m_failed || !isRunning() ) + if( unlikely( m_failed || !isRunning() ) ) { if( _out_buf != NULL ) { @@ -160,7 +160,7 @@ bool RemotePlugin::process( const sampleFrame * _in_buf, return false; } - if( m_shm == NULL ) + if( unlikely( m_shm == NULL ) ) { // m_shm being zero means we didn't initialize everything so // far so process one message each time (and hope we get @@ -227,8 +227,7 @@ bool RemotePlugin::process( const sampleFrame * _in_buf, waitForMessage( IdProcessingDone ); unlock(); - const ch_cnt_t outputs = qMin( m_outputCount, - DEFAULT_CHANNELS ); + const ch_cnt_t outputs = qMin( m_outputCount, DEFAULT_CHANNELS ); if( m_splitChannels ) { for( ch_cnt_t ch = 0; ch < outputs; ++ch ) @@ -328,7 +327,7 @@ void RemotePlugin::resizeSharedProcessingMemory() bool RemotePlugin::processMessage( const message & _m ) { lock(); - message reply_message( _m.id ); + message replyMessage( _m.id ); bool reply = false; switch( _m.id ) { @@ -341,12 +340,12 @@ bool RemotePlugin::processMessage( const message & _m ) case IdSampleRateInformation: reply = true; - reply_message.addInt( engine::getMixer()->processingSampleRate() ); + replyMessage.addInt( engine::getMixer()->processingSampleRate() ); break; case IdBufferSizeInformation: reply = true; - reply_message.addInt( engine::getMixer()->framesPerPeriod() ); + replyMessage.addInt( engine::getMixer()->framesPerPeriod() ); break; case IdChangeInputCount: @@ -371,7 +370,7 @@ bool RemotePlugin::processMessage( const message & _m ) } if( reply ) { - sendMessage( reply_message ); + sendMessage( replyMessage ); } unlock();