monotone

monotone Mtn Source Tree

Root/botan/timers.cpp

1/*************************************************
2* Timestamp Functions Source File *
3* (C) 1999-2005 The Botan Project *
4*************************************************/
5
6#include <botan/timers.h>
7#include <botan/util.h>
8#include <botan/init.h>
9#include <ctime>
10
11namespace Botan {
12
13namespace {
14
15Timer* global_timer = 0;
16
17}
18
19/*************************************************
20* Timer Access Functions *
21*************************************************/
22u64bit system_time()
23 {
24 return std::time(0);
25 }
26
27u64bit system_clock()
28 {
29 if(!global_timer)
30 return combine_timers(std::time(0), std::clock(), CLOCKS_PER_SEC);
31 return global_timer->clock();
32 }
33
34/*************************************************
35* Combine a two time values into a single one *
36*************************************************/
37u64bit combine_timers(u32bit seconds, u32bit parts, u32bit parts_hz)
38 {
39 const u64bit NANOSECONDS_UNITS = 1000000000;
40 parts *= (NANOSECONDS_UNITS / parts_hz);
41 return ((seconds * NANOSECONDS_UNITS) + parts);
42 }
43
44namespace Init {
45
46/*************************************************
47* Set the Timer type *
48*************************************************/
49void set_timer_type(Timer* timer)
50 {
51 delete global_timer;
52 global_timer = timer;
53 }
54
55}
56
57}

Archive Download this file

Branches

Tags

Quick Links:     www.monotone.ca    -     Downloads    -     Documentation    -     Wiki    -     Code Forge    -     Build Status