00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "JackProcessSync.h"
00021 #include "JackError.h"
00022
00023 namespace Jack
00024 {
00025
00026 bool JackProcessSync::TimedWait(long usec)
00027 {
00028 struct timeval T0, T1;
00029 timespec time;
00030 struct timeval now;
00031 int res;
00032
00033 pthread_mutex_lock(&fLock);
00034 jack_log("JackProcessSync::TimedWait time out = %ld", usec);
00035 gettimeofday(&T0, 0);
00036
00037 gettimeofday(&now, 0);
00038 unsigned int next_date_usec = now.tv_usec + usec;
00039 time.tv_sec = now.tv_sec + (next_date_usec / 1000000);
00040 time.tv_nsec = (next_date_usec % 1000000) * 1000;
00041 res = pthread_cond_timedwait(&fCond, &fLock, &time);
00042 if (res != 0)
00043 jack_error("pthread_cond_timedwait error usec = %ld err = %s", usec, strerror(res));
00044
00045 gettimeofday(&T1, 0);
00046 pthread_mutex_unlock(&fLock);
00047 jack_log("JackProcessSync::TimedWait finished delta = %5.1lf",
00048 (1e6 * T1.tv_sec - 1e6 * T0.tv_sec + T1.tv_usec - T0.tv_usec));
00049 return (res == 0);
00050 }
00051
00052 void JackProcessSync::Wait()
00053 {
00054 int res;
00055 pthread_mutex_lock(&fLock);
00056
00057 if ((res = pthread_cond_wait(&fCond, &fLock)) != 0)
00058 jack_error("pthread_cond_wait error err = %s", strerror(errno));
00059 pthread_mutex_unlock(&fLock);
00060
00061 }
00062
00063 bool JackInterProcessSync::TimedWait(long usec)
00064 {
00065 struct timeval T0, T1;
00066
00067 gettimeofday(&T0, 0);
00068 bool res = fSynchro->TimedWait(usec);
00069 gettimeofday(&T1, 0);
00070
00071 return res;
00072 }
00073
00074 }
00075