tbx  0.7.5
monotonictime.h
1 /*
2  * tbx RISC OS toolbox library
3  *
4  * Copyright (C) 2010 Alan Buckley All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 /*
25  * montonictime.h
26  *
27  * Created on: 20 Oct 2010
28  * Author: alanb
29  */
30 
31 #ifndef TBX_MONTONICTIME_H_
32 #define TBX_MONTONICTIME_H_
33 
34 #include "swis.h"
35 namespace tbx
36 {
45  inline unsigned int monotonic_time()
46  {
47  unsigned int mt;
48  _swix(OS_ReadMonotonicTime, _OUT(0), &mt);
49  return mt;
50  }
51 
59  inline unsigned int monotonic_elapsed(unsigned int from, unsigned int to)
60  {
61  if (to >= from) return to - from;
62  return to + (0xFFFFFFFF ^ from) + 1;
63  }
64 
73  inline bool monotonic_lt(unsigned int compare, unsigned int to)
74  {
75  if (to >= compare) return false;
76  return (compare - to) > 0x7FFFFFFF;
77  }
78 
87  inline bool monotonic_le(unsigned int compare, unsigned int to)
88  {
89  if (to > compare) return false;
90  if (to == compare) return true;
91  return (compare - to) > 0x7FFFFFFF;
92  }
93 
102  inline bool monotonic_gt(unsigned int compare, unsigned int to)
103  {
104  if (compare > to) return true;
105  return (compare - to) < 0x7FFFFFFF;
106  }
107 
116  inline bool monotonic_ge(unsigned int compare, unsigned int to)
117  {
118  if (compare > to) return true;
119  if (compare == to) return true;
120  return (compare - to) < 0x7FFFFFFF;
121  }
122 }
123 
124 #endif /* TBX_MONTONICTIME_H_ */
A library for creating RISC OS toolbox applications.
Definition: abouttobeshownlistener.cc:34
unsigned int monotonic_elapsed(unsigned int from, unsigned int to)
Return the elapsed time taking into account the wrap around for unsigned integers.
Definition: monotonictime.h:59
unsigned int monotonic_time()
Read the time in centiseconds since the system was last reset.
Definition: monotonictime.h:45
bool monotonic_lt(unsigned int compare, unsigned int to)
Compare if one time is less than another taking into account wrap around.
Definition: monotonictime.h:73
bool monotonic_ge(unsigned int compare, unsigned int to)
Compare if one time is greater than or equal to another taking into account wrap around.
Definition: monotonictime.h:116
bool monotonic_gt(unsigned int compare, unsigned int to)
Compare if one time is greater than another taking into account wrap around.
Definition: monotonictime.h:102
bool monotonic_le(unsigned int compare, unsigned int to)
Compare if one time is less than or equals to another taking into account wrap around.
Definition: monotonictime.h:87