浏览代码

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

master
kevin 11 年前
父节点
当前提交
b3b492f094
共有 7 个文件被更改,包括 23 次插入18 次删除
  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 查看文件

@@ -10,7 +10,6 @@
10 10
 
11 11
 #include "cmApBuf.h"  // only needed for cmApBufTest().
12 12
 
13
-//#include <unistd.h> // usleep
14 13
 
15 14
 enum
16 15
 {
@@ -338,7 +337,6 @@ cmAgRC_t      cmApAggDeviceStart( unsigned aggDevIdx )
338 337
     if( cmApDeviceStart( physDevIdx ) != kOkApRC )
339 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 342
   ap->startedFl = true;

+ 1
- 2
cmAudioFileDev.c 查看文件

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

+ 1
- 1
cmAudioNrtDev.c 查看文件

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

+ 3
- 4
cmMidiFilePlay.c 查看文件

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

+ 11
- 6
cmThread.c 查看文件

@@ -60,7 +60,7 @@ void* _cmThThreadCallback(void* param)
60 60
 
61 61
     if( t->state == kPausedThId )
62 62
     {
63
-      usleep( t->pauseMicroSecs );
63
+      cmSleepUs( t->pauseMicroSecs );
64 64
 
65 65
       if( cmIsFlag(t->doFlags,kDoRunThFl) )
66 66
       {
@@ -104,8 +104,8 @@ cmThRC_t _cmThWaitForState( cmThThread_t* t, unsigned stateId )
104 104
 
105 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 109
     waitTimeMicroSecs += 15000; //t->waitMicroSecs;
110 110
   }
111 111
 
@@ -1671,7 +1671,7 @@ bool _cmTsQueueCb0(void* param)
1671 1671
     printf("in error %i\n",p->id);
1672 1672
   
1673 1673
 
1674
-  usleep(100*1000);
1674
+  cmSleepUs(100*1000);
1675 1675
 
1676 1676
   return true;
1677 1677
 }
@@ -1794,7 +1794,7 @@ bool _cmTs1p1cCb0(void* param)
1794 1794
   
1795 1795
   ++p->id;
1796 1796
 
1797
-  usleep(100*1000);
1797
+  cmSleepUs(100*1000);
1798 1798
 
1799 1799
   return true;
1800 1800
 }
@@ -1905,7 +1905,7 @@ bool _cmTsMp1cCb0(void* param)
1905 1905
   else
1906 1906
     printf("in error %i\n",p->id);
1907 1907
 
1908
-  usleep(100*1000);
1908
+  cmSleepUs(100*1000);
1909 1909
 
1910 1910
   return true;
1911 1911
 }
@@ -1995,3 +1995,8 @@ void cmTsMp1cTest( cmRpt_t* rpt )
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 查看文件

@@ -270,6 +270,10 @@ extern "C" {
270 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 278
   void cmTsQueueTest( cmRpt_t* rpt );
275 279
   void cmTs1p1cTest( cmRpt_t* rpt );

+ 3
- 3
dsp/cmDspNet.c 查看文件

@@ -98,7 +98,7 @@ cmDspRC_t _cmDspSysNetSend( cmDsp_t* p, unsigned remoteNetNodeId, unsigned subSe
98 98
 
99 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 103
   else
104 104
   {
@@ -223,7 +223,7 @@ cmDspRC_t _cmDspSysNetSendConnRequests( cmDsp_t* p, unsigned dstNetNodeId )
223 223
       if( p->netVerbosity > 1 )
224 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,7 +363,7 @@ bool _cmDspSysNetSyncThreadCb( void* param )
363 363
   }
364 364
 
365 365
   // prevent the thread from burning too much time
366
-  usleep(p->sendWaitMs*1000);
366
+  cmSleepUs(p->sendWaitMs*1000);
367 367
   
368 368
   // check if all nodes have completed transmission to this node
369 369
   nodeFl = _cmDspSysNetCheckNetNodeStatus(p);

正在加载...
取消
保存