Browse Source

cmThread.h/c: cmSleepMs() and cmSleepUs() and replaced all references to usleep() in many files.

master
kevin 11 years ago
parent
commit
b3b492f094
7 changed files with 23 additions and 18 deletions
  1. 0
    2
      cmAudioAggDev.c
  2. 1
    2
      cmAudioFileDev.c
  3. 1
    1
      cmAudioNrtDev.c
  4. 3
    4
      cmMidiFilePlay.c
  5. 11
    6
      cmThread.c
  6. 4
    0
      cmThread.h
  7. 3
    3
      dsp/cmDspNet.c

+ 0
- 2
cmAudioAggDev.c View File

10
 
10
 
11
 #include "cmApBuf.h"  // only needed for cmApBufTest().
11
 #include "cmApBuf.h"  // only needed for cmApBufTest().
12
 
12
 
13
-//#include <unistd.h> // usleep
14
 
13
 
15
 enum
14
 enum
16
 {
15
 {
338
     if( cmApDeviceStart( physDevIdx ) != kOkApRC )
337
     if( cmApDeviceStart( physDevIdx ) != kOkApRC )
339
       return cmErrMsg(&_cmAg.err,kPhysDevStartFailAgRC,"The physical device (index:%i '%s') start failed.",physDevIdx,cmStringNullGuard(cmApDeviceLabel(physDevIdx)));
338
       return cmErrMsg(&_cmAg.err,kPhysDevStartFailAgRC,"The physical device (index:%i '%s') start failed.",physDevIdx,cmStringNullGuard(cmApDeviceLabel(physDevIdx)));
340
 
339
 
341
-    //usleep(1000);
342
   }
340
   }
343
 
341
 
344
   ap->startedFl = true;
342
   ap->startedFl = true;

+ 1
- 2
cmAudioFileDev.c View File

9
 #include "cmAudioPort.h"
9
 #include "cmAudioPort.h"
10
 #include "cmAudioFileDev.h"
10
 #include "cmAudioFileDev.h"
11
 
11
 
12
-#include <unistd.h> // usleep()
13
 
12
 
14
 #ifdef OS_OSX
13
 #ifdef OS_OSX
15
 #include "osx/clock_gettime_stub.h"
14
 #include "osx/clock_gettime_stub.h"
168
     // if the execution time has not yet arrived
167
     // if the execution time has not yet arrived
169
     if( dusec > 0 )
168
     if( dusec > 0 )
170
     {
169
     {
171
-      usleep(dusec);
170
+      cmSleepUs(dusec);
172
     }
171
     }
173
 
172
 
174
     // if the thread is still running
173
     // if the thread is still running

+ 1
- 1
cmAudioNrtDev.c View File

130
 {
130
 {
131
   cmApNrtDev_t* dp = (cmApNrtDev_t*)param;
131
   cmApNrtDev_t* dp = (cmApNrtDev_t*)param;
132
 
132
 
133
-  usleep( dp->cbPeriodMs * 1000 );
133
+  cmSleepUs( dp->cbPeriodMs * 1000 );
134
 
134
 
135
 
135
 
136
   cmApAudioPacket_t pkt;
136
   cmApAudioPacket_t pkt;

+ 3
- 4
cmMidiFilePlay.c View File

1
 #include <sys/time.h>  // gettimeofday()
1
 #include <sys/time.h>  // gettimeofday()
2
-#include <unistd.h>    // usleep()
3
-//#include <time.h>      // clock_gettime()
4
 #include "cmPrefix.h"
2
 #include "cmPrefix.h"
5
 #include "cmGlobal.h"
3
 #include "cmGlobal.h"
6
 #include "cmRpt.h"
4
 #include "cmRpt.h"
13
 #include "cmMidiPort.h"
11
 #include "cmMidiPort.h"
14
 #include "cmMidiFile.h"
12
 #include "cmMidiFile.h"
15
 #include "cmMidiFilePlay.h"
13
 #include "cmMidiFilePlay.h"
14
+#include "cmThread.h" // cmSleepUs()
16
 
15
 
17
 #ifdef OS_OSX
16
 #ifdef OS_OSX
18
 #include "osx/clock_gettime_stub.h"
17
 #include "osx/clock_gettime_stub.h"
293
 
292
 
294
   for(i=0; i<n; ++i)
293
   for(i=0; i<n; ++i)
295
   {
294
   {
296
-    usleep(suspendUsecs);
295
+    cmSleepUs(suspendUsecs);
297
 
296
 
298
     
297
     
299
     clock_gettime(CLOCK_REALTIME,&t1);
298
     clock_gettime(CLOCK_REALTIME,&t1);
358
   //for(i=0; i<n; ++i)
357
   //for(i=0; i<n; ++i)
359
   while(rc != kEndOfFileMfpRC)
358
   while(rc != kEndOfFileMfpRC)
360
   {
359
   {
361
-    usleep(suspendUsecs);
360
+    cmSleepUs(suspendUsecs);
362
     
361
     
363
     clock_gettime(CLOCK_REALTIME,&t1);    
362
     clock_gettime(CLOCK_REALTIME,&t1);    
364
     t1.tv_sec -= base.tv_sec;
363
     t1.tv_sec -= base.tv_sec;

+ 11
- 6
cmThread.c View File

60
 
60
 
61
     if( t->state == kPausedThId )
61
     if( t->state == kPausedThId )
62
     {
62
     {
63
-      usleep( t->pauseMicroSecs );
63
+      cmSleepUs( t->pauseMicroSecs );
64
 
64
 
65
       if( cmIsFlag(t->doFlags,kDoRunThFl) )
65
       if( cmIsFlag(t->doFlags,kDoRunThFl) )
66
       {
66
       {
104
 
104
 
105
   while( t->state != stateId && waitTimeMicroSecs < t->waitMicroSecs )
105
   while( t->state != stateId && waitTimeMicroSecs < t->waitMicroSecs )
106
   {
106
   {
107
-    //usleep( t->waitMicroSecs );
108
-    usleep( 15000 );
107
+    //cmSleepUs( t->waitMicroSecs );
108
+    cmSleepUs( 15000 );
109
     waitTimeMicroSecs += 15000; //t->waitMicroSecs;
109
     waitTimeMicroSecs += 15000; //t->waitMicroSecs;
110
   }
110
   }
111
 
111
 
1671
     printf("in error %i\n",p->id);
1671
     printf("in error %i\n",p->id);
1672
   
1672
   
1673
 
1673
 
1674
-  usleep(100*1000);
1674
+  cmSleepUs(100*1000);
1675
 
1675
 
1676
   return true;
1676
   return true;
1677
 }
1677
 }
1794
   
1794
   
1795
   ++p->id;
1795
   ++p->id;
1796
 
1796
 
1797
-  usleep(100*1000);
1797
+  cmSleepUs(100*1000);
1798
 
1798
 
1799
   return true;
1799
   return true;
1800
 }
1800
 }
1905
   else
1905
   else
1906
     printf("in error %i\n",p->id);
1906
     printf("in error %i\n",p->id);
1907
 
1907
 
1908
-  usleep(100*1000);
1908
+  cmSleepUs(100*1000);
1909
 
1909
 
1910
   return true;
1910
   return true;
1911
 }
1911
 }
1995
   
1995
   
1996
 }
1996
 }
1997
 
1997
 
1998
+void cmSleepUs( unsigned microseconds )
1999
+{ usleep(microseconds); }
2000
+
2001
+void cmSleepMs( unsigned milliseconds )
2002
+{ cmSleepUs(milliseconds*1000); }

+ 4
- 0
cmThread.h View File

270
   bool       cmTsMp1cIsValid( cmTsMp1cH_t h );  
270
   bool       cmTsMp1cIsValid( cmTsMp1cH_t h );  
271
 
271
 
272
 
272
 
273
+  // Sleep functions
274
+  void cmSleepUs( unsigned microseconds );
275
+  void cmSleepMs( unsigned milliseconds );
276
+
273
 
277
 
274
   void cmTsQueueTest( cmRpt_t* rpt );
278
   void cmTsQueueTest( cmRpt_t* rpt );
275
   void cmTs1p1cTest( cmRpt_t* rpt );
279
   void cmTs1p1cTest( cmRpt_t* rpt );

+ 3
- 3
dsp/cmDspNet.c View File

98
 
98
 
99
   if( cmUdpNetSendById(p->netH, remoteNetNodeId, &m, sizeof(m) ) == kOkUnRC )
99
   if( cmUdpNetSendById(p->netH, remoteNetNodeId, &m, sizeof(m) ) == kOkUnRC )
100
   {
100
   {
101
-    //usleep(p->sendWaitMs*1000);
101
+    //cmSleepUs(p->sendWaitMs*1000);
102
   }
102
   }
103
   else
103
   else
104
   {
104
   {
223
       if( p->netVerbosity > 1 )
223
       if( p->netVerbosity > 1 )
224
         cmRptPrintf(p->err.rpt,"Sync: send req to %i\n",rp->dstNetNodeId);
224
         cmRptPrintf(p->err.rpt,"Sync: send req to %i\n",rp->dstNetNodeId);
225
 
225
 
226
-      //usleep(p->sendWaitMs*1000); // wait  between transmissions
226
+      //cmSleepUs(p->sendWaitMs*1000); // wait  between transmissions
227
     }
227
     }
228
 
228
 
229
   }
229
   }
363
   }
363
   }
364
 
364
 
365
   // prevent the thread from burning too much time
365
   // prevent the thread from burning too much time
366
-  usleep(p->sendWaitMs*1000);
366
+  cmSleepUs(p->sendWaitMs*1000);
367
   
367
   
368
   // check if all nodes have completed transmission to this node
368
   // check if all nodes have completed transmission to this node
369
   nodeFl = _cmDspSysNetCheckNetNodeStatus(p);
369
   nodeFl = _cmDspSysNetCheckNetNodeStatus(p);

Loading…
Cancel
Save