From b3b492f09407e6d57e23496ed10ce8382da0adf4 Mon Sep 17 00:00:00 2001 From: kevin Date: Mon, 8 Apr 2013 22:56:30 -0700 Subject: [PATCH] cmThread.h/c: cmSleepMs() and cmSleepUs() and replaced all references to usleep() in many files. --- cmAudioAggDev.c | 2 -- cmAudioFileDev.c | 3 +-- cmAudioNrtDev.c | 2 +- cmMidiFilePlay.c | 7 +++---- cmThread.c | 17 +++++++++++------ cmThread.h | 4 ++++ dsp/cmDspNet.c | 6 +++--- 7 files changed, 23 insertions(+), 18 deletions(-) diff --git a/cmAudioAggDev.c b/cmAudioAggDev.c index b9c9617..ff5dfa1 100644 --- a/cmAudioAggDev.c +++ b/cmAudioAggDev.c @@ -10,7 +10,6 @@ #include "cmApBuf.h" // only needed for cmApBufTest(). -//#include // usleep enum { @@ -338,7 +337,6 @@ cmAgRC_t cmApAggDeviceStart( unsigned aggDevIdx ) if( cmApDeviceStart( physDevIdx ) != kOkApRC ) return cmErrMsg(&_cmAg.err,kPhysDevStartFailAgRC,"The physical device (index:%i '%s') start failed.",physDevIdx,cmStringNullGuard(cmApDeviceLabel(physDevIdx))); - //usleep(1000); } ap->startedFl = true; diff --git a/cmAudioFileDev.c b/cmAudioFileDev.c index 8be3080..b5a4610 100644 --- a/cmAudioFileDev.c +++ b/cmAudioFileDev.c @@ -9,7 +9,6 @@ #include "cmAudioPort.h" #include "cmAudioFileDev.h" -#include // usleep() #ifdef OS_OSX #include "osx/clock_gettime_stub.h" @@ -168,7 +167,7 @@ bool _cmAudioDevThreadFunc(void* param) // if the execution time has not yet arrived if( dusec > 0 ) { - usleep(dusec); + cmSleepUs(dusec); } // if the thread is still running diff --git a/cmAudioNrtDev.c b/cmAudioNrtDev.c index 08ac125..1f3def4 100644 --- a/cmAudioNrtDev.c +++ b/cmAudioNrtDev.c @@ -130,7 +130,7 @@ bool cmApNrtThreadFunc(void* param) { cmApNrtDev_t* dp = (cmApNrtDev_t*)param; - usleep( dp->cbPeriodMs * 1000 ); + cmSleepUs( dp->cbPeriodMs * 1000 ); cmApAudioPacket_t pkt; diff --git a/cmMidiFilePlay.c b/cmMidiFilePlay.c index 6b04ab2..e761d9b 100644 --- a/cmMidiFilePlay.c +++ b/cmMidiFilePlay.c @@ -1,6 +1,4 @@ #include // gettimeofday() -#include // usleep() -//#include // clock_gettime() #include "cmPrefix.h" #include "cmGlobal.h" #include "cmRpt.h" @@ -13,6 +11,7 @@ #include "cmMidiPort.h" #include "cmMidiFile.h" #include "cmMidiFilePlay.h" +#include "cmThread.h" // cmSleepUs() #ifdef OS_OSX #include "osx/clock_gettime_stub.h" @@ -293,7 +292,7 @@ void _cmMfpTestTimer() for(i=0; istate == kPausedThId ) { - usleep( t->pauseMicroSecs ); + cmSleepUs( t->pauseMicroSecs ); if( cmIsFlag(t->doFlags,kDoRunThFl) ) { @@ -104,8 +104,8 @@ cmThRC_t _cmThWaitForState( cmThThread_t* t, unsigned stateId ) while( t->state != stateId && waitTimeMicroSecs < t->waitMicroSecs ) { - //usleep( t->waitMicroSecs ); - usleep( 15000 ); + //cmSleepUs( t->waitMicroSecs ); + cmSleepUs( 15000 ); waitTimeMicroSecs += 15000; //t->waitMicroSecs; } @@ -1671,7 +1671,7 @@ bool _cmTsQueueCb0(void* param) printf("in error %i\n",p->id); - usleep(100*1000); + cmSleepUs(100*1000); return true; } @@ -1794,7 +1794,7 @@ bool _cmTs1p1cCb0(void* param) ++p->id; - usleep(100*1000); + cmSleepUs(100*1000); return true; } @@ -1905,7 +1905,7 @@ bool _cmTsMp1cCb0(void* param) else printf("in error %i\n",p->id); - usleep(100*1000); + cmSleepUs(100*1000); return true; } @@ -1995,3 +1995,8 @@ void cmTsMp1cTest( cmRpt_t* rpt ) } +void cmSleepUs( unsigned microseconds ) +{ usleep(microseconds); } + +void cmSleepMs( unsigned milliseconds ) +{ cmSleepUs(milliseconds*1000); } diff --git a/cmThread.h b/cmThread.h index b43ba35..411ed6b 100644 --- a/cmThread.h +++ b/cmThread.h @@ -270,6 +270,10 @@ extern "C" { bool cmTsMp1cIsValid( cmTsMp1cH_t h ); + // Sleep functions + void cmSleepUs( unsigned microseconds ); + void cmSleepMs( unsigned milliseconds ); + void cmTsQueueTest( cmRpt_t* rpt ); void cmTs1p1cTest( cmRpt_t* rpt ); diff --git a/dsp/cmDspNet.c b/dsp/cmDspNet.c index 49a5e0a..de6742c 100644 --- a/dsp/cmDspNet.c +++ b/dsp/cmDspNet.c @@ -98,7 +98,7 @@ cmDspRC_t _cmDspSysNetSend( cmDsp_t* p, unsigned remoteNetNodeId, unsigned subSe if( cmUdpNetSendById(p->netH, remoteNetNodeId, &m, sizeof(m) ) == kOkUnRC ) { - //usleep(p->sendWaitMs*1000); + //cmSleepUs(p->sendWaitMs*1000); } else { @@ -223,7 +223,7 @@ cmDspRC_t _cmDspSysNetSendConnRequests( cmDsp_t* p, unsigned dstNetNodeId ) if( p->netVerbosity > 1 ) cmRptPrintf(p->err.rpt,"Sync: send req to %i\n",rp->dstNetNodeId); - //usleep(p->sendWaitMs*1000); // wait between transmissions + //cmSleepUs(p->sendWaitMs*1000); // wait between transmissions } } @@ -363,7 +363,7 @@ bool _cmDspSysNetSyncThreadCb( void* param ) } // prevent the thread from burning too much time - usleep(p->sendWaitMs*1000); + cmSleepUs(p->sendWaitMs*1000); // check if all nodes have completed transmission to this node nodeFl = _cmDspSysNetCheckNetNodeStatus(p);