From 91daeb332fc68bd1230e808285562c669022d930 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Mon, 29 Aug 2011 15:28:11 +1000 Subject: [PATCH] Add simple time functions --- Makefile.am | 2 ++ time.cpp | 33 +++++++++++++++++++++++++++++++++ time.hpp | 29 +++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 time.cpp create mode 100644 time.hpp diff --git a/Makefile.am b/Makefile.am index 806f23a9..48eae25b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -31,6 +31,7 @@ UTIL_INCLUDE = \ stream.hpp \ string.hpp \ si.hpp \ + time.hpp \ types.hpp \ vector.hpp \ version.hpp @@ -56,6 +57,7 @@ UTIL_FILES = \ stream.cpp \ string.cpp \ si.cpp \ + time.cpp \ types.cpp \ vector.cpp \ version.cpp diff --git a/time.cpp b/time.cpp new file mode 100644 index 00000000..d54da777 --- /dev/null +++ b/time.cpp @@ -0,0 +1,33 @@ +/* + * This file is part of libgim. + * + * libgim is free software: you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * libgim is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with libgim. If not, see . + * + * Copyright 2010 Danny Robson + */ + +#include "time.hpp" + +#include + +using namespace util; + + +uint64_t +util::nanoseconds (void) { + struct timespec t; + clock_gettime (CLOCK_REALTIME, &t); + + return t.tv_sec * 1000000000 + t.tv_nsec; +} diff --git a/time.hpp b/time.hpp new file mode 100644 index 00000000..ff9716b6 --- /dev/null +++ b/time.hpp @@ -0,0 +1,29 @@ +/* + * This file is part of libgim. + * + * libgim is free software: you can redistribute it and/or modify it under the + * terms of the GNU General Public License as published by the Free Software + * Foundation, either version 3 of the License, or (at your option) any later + * version. + * + * libgim is distributed in the hope that it will be useful, but WITHOUT ANY + * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more + * details. + * + * You should have received a copy of the GNU General Public License + * along with libgim. If not, see . + * + * Copyright 2010 Danny Robson + */ + +#ifndef __UTIL_TIME_HPP +#define __UTIL_TIME_HPP + +#include + +namespace util { + uint64_t nanoseconds (void); +} + +#endif // __UTIL_TIME_HPP