2 Copyright (C) 1998-99 Paul Barton-Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 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 General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #ifndef __precision_timer_h__
22 #define __precision_timer_h__
24 #include <pbd/cycles.h>
26 typedef cycles_t precision_time_t;
28 class PrecisionTimer {
32 /* returns current time in microseconds since
33 the time base was created (which may be
34 the same as when the PrecisionTimer was
35 created or it may not).
38 #ifdef PBD_HAVE_CYCLE_COUNTER
40 precision_time_t current () {
41 return get_cycles() / cycles_per_usec;
44 #else /* !HAVE_CYCLE_COUNTER */
46 precision_time_t current () {
48 gettimeofday (&now, 0);
49 return (precision_time_t) ((now.tv_sec * 1000000) + now.tv_usec);
52 #endif /* HAVE_CYCLE_COUNTER */
56 static precision_time_t cycles_per_usec;
59 #endif // __precision_timer.h