Switch to unified view

a/sc2src/chrono.h b/sc2src/chrono.h
1
/* Copyright (C) 2016 J.F.Dockes
2
 *   This program is free software; you can redistribute it and/or modify
3
 *   it under the terms of the GNU General Public License as published by
4
 *   the Free Software Foundation; either version 2 of the License, or
5
 *   (at your option) any later version.
6
 *
7
 *   This program is distributed in the hope that it will be useful,
8
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
 *   GNU General Public License for more details.
11
 *
12
 *   You should have received a copy of the GNU General Public License
13
 *   along with this program; if not, write to the
14
 *   Free Software Foundation, Inc.,
15
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
16
 */
1
#ifndef _CHRONO_H_
17
#ifndef _CHRONO_H_
2
#define _CHRONO_H_
18
#define _CHRONO_H_
19
#include <chrono>
3
20
4
/** Easy interface to measuring time intervals */
21
/** Easy interface to measuring time intervals */
5
class Chrono {
22
class Chrono {
6
public:
23
public:
7
    /** Initialize, setting the origin time */
24
    /** Initialize, setting the origin time */
...
...
17
34
18
    /** Return interval value in various units.
35
    /** Return interval value in various units.
19
     *
36
     *
20
     * Frozen means give time since the last refnow call (this is to
37
     * Frozen means give time since the last refnow call (this is to
21
     * allow for using one actual system call to get values from many
38
     * allow for using one actual system call to get values from many
22
     * chrono objects, like when examining timeouts in a queue 
39
     * chrono objects, like when examining timeouts in a queue
23
     */
40
     */
24
    long millis(bool frozen = false);
41
    long millis(bool frozen = false);
25
    long micros(bool frozen = false);
42
    long micros(bool frozen = false);
26
    float secs(bool frozen = false);
43
    float secs(bool frozen = false);
27
44
28
    /** Return current orig */
29
    long long amicros() const;
30
31
    struct TimeSpec {
32
        time_t tv_sec; /* Time in seconds */
33
        long   tv_nsec; /* And nanoseconds (< 10E9) */
34
    };
35
36
private:
45
private:
46
    typedef std::chrono::time_point<std::chrono::steady_clock> TimePoint;
37
    TimeSpec m_orig;
47
    TimePoint m_orig;
38
    static TimeSpec o_now;
48
    static TimePoint o_now;
39
};
49
};
40
50
41
#endif /* _CHRONO_H_ */
51
#endif /* _CHRONO_H_ */