2 Copyright (C) 2004-2008 Grame
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU Lesser General Public License as published by
6 the Free Software Foundation; either version 2.1 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include "JackProcessSync.h"
21 #include "JackError.h"
26 bool JackProcessSync::TimedWait(long usec
)
28 struct timeval T0
, T1
;
33 pthread_mutex_lock(&fLock
);
34 jack_log("JackProcessSync::TimedWait time out = %ld", usec
);
37 gettimeofday(&now
, 0);
38 unsigned int next_date_usec
= now
.tv_usec
+ usec
;
39 time
.tv_sec
= now
.tv_sec
+ (next_date_usec
/ 1000000);
40 time
.tv_nsec
= (next_date_usec
% 1000000) * 1000;
41 res
= pthread_cond_timedwait(&fCond
, &fLock
, &time
);
43 jack_error("pthread_cond_timedwait error usec = %ld err = %s", usec
, strerror(res
));
46 pthread_mutex_unlock(&fLock
);
47 jack_log("JackProcessSync::TimedWait finished delta = %5.1lf",
48 (1e6
* T1
.tv_sec
- 1e6
* T0
.tv_sec
+ T1
.tv_usec
- T0
.tv_usec
));
52 void JackProcessSync::Wait()
55 pthread_mutex_lock(&fLock
);
56 //jack_log("JackProcessSync::Wait...");
57 if ((res
= pthread_cond_wait(&fCond
, &fLock
)) != 0)
58 jack_error("pthread_cond_wait error err = %s", strerror(errno
));
59 pthread_mutex_unlock(&fLock
);
60 //jack_log("JackProcessSync::Wait finished");
63 bool JackInterProcessSync::TimedWait(long usec
)
65 struct timeval T0
, T1
;
66 //jack_log("JackInterProcessSync::TimedWait...");
68 bool res
= fSynchro
->TimedWait(usec
);
70 //jack_log("JackInterProcessSync::TimedWait finished delta = %5.1lf", (1e6 * T1.tv_sec - 1e6 * T0.tv_sec + T1.tv_usec - T0.tv_usec));