Merge misc_os_dependent.h into time_helper.h
Actions: * Move get_ns_count(), get_tick_count(), and get_gmt_time() from misc_os_dependent.h to time_helper.h. I did this because all those functions are time-related and under the same namespace * Remove misc_os_dependent.h because it is now empty * Change all includes of misc_os_dependent.h to time_helper.h where appropriate * Remove get_time_string*() from time_helper.h b/c its unused * Remove get_time_t_from_ole_date() from time_helper.h b/c its unused * Remove odbc_time_to_oledb_taime() from time_helper.h b/c its unused * Refactor get_ns_count() to use std::chrono instead of 4 different implementation-specific hacks
This commit is contained in:
parent
4b3d9de65b
commit
9a59b131c4
|
@ -37,8 +37,8 @@
|
|||
#include <boost/uuid/uuid.hpp>
|
||||
#include <boost/uuid/random_generator.hpp>
|
||||
|
||||
#include "misc_os_dependent.h"
|
||||
#include "syncobj.h"
|
||||
#include "time_helper.h"
|
||||
|
||||
namespace epee
|
||||
{
|
||||
|
|
|
@ -1,102 +0,0 @@
|
|||
// Copyright (c) 2006-2013, Andrey N. Sabelnikov, www.sabelnikov.net
|
||||
// All rights reserved.
|
||||
//
|
||||
// Redistribution and use in source and binary forms, with or without
|
||||
// modification, are permitted provided that the following conditions are met:
|
||||
// * Redistributions of source code must retain the above copyright
|
||||
// notice, this list of conditions and the following disclaimer.
|
||||
// * Redistributions in binary form must reproduce the above copyright
|
||||
// notice, this list of conditions and the following disclaimer in the
|
||||
// documentation and/or other materials provided with the distribution.
|
||||
// * Neither the name of the Andrey N. Sabelnikov nor the
|
||||
// names of its contributors may be used to endorse or promote products
|
||||
// derived from this software without specific prior written permission.
|
||||
//
|
||||
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
// WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER BE LIABLE FOR ANY
|
||||
// DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
// (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
// LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
// ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
//
|
||||
#ifdef _WIN32
|
||||
#include <winsock2.h>
|
||||
#endif
|
||||
|
||||
#ifdef WIN32
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#endif
|
||||
|
||||
//#ifdef _WIN32_WINNT
|
||||
// #undef _WIN32_WINNT
|
||||
// #define _WIN32_WINNT 0x0600
|
||||
//#endif
|
||||
|
||||
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#ifdef __MACH__
|
||||
#include <mach/clock.h>
|
||||
#include <mach/mach.h>
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <ctime>
|
||||
|
||||
#pragma once
|
||||
namespace epee
|
||||
{
|
||||
namespace misc_utils
|
||||
{
|
||||
|
||||
inline uint64_t get_ns_count()
|
||||
{
|
||||
#if defined(_MSC_VER)
|
||||
return ::GetTickCount64() * 1000000;
|
||||
#elif defined(WIN32)
|
||||
static LARGE_INTEGER pcfreq = {0};
|
||||
LARGE_INTEGER ticks;
|
||||
if (!pcfreq.QuadPart)
|
||||
QueryPerformanceFrequency(&pcfreq);
|
||||
QueryPerformanceCounter(&ticks);
|
||||
ticks.QuadPart *= 1000000000; /* we want nsec */
|
||||
return ticks.QuadPart / pcfreq.QuadPart;
|
||||
#elif defined(__MACH__)
|
||||
clock_serv_t cclock;
|
||||
mach_timespec_t mts;
|
||||
|
||||
host_get_clock_service(mach_host_self(), SYSTEM_CLOCK, &cclock);
|
||||
clock_get_time(cclock, &mts);
|
||||
mach_port_deallocate(mach_task_self(), cclock);
|
||||
|
||||
return ((uint64_t)mts.tv_sec * 1000000000) + (mts.tv_nsec);
|
||||
#else
|
||||
struct timespec ts;
|
||||
if(clock_gettime(CLOCK_MONOTONIC, &ts) != 0) {
|
||||
return 0;
|
||||
}
|
||||
return ((uint64_t)ts.tv_sec * 1000000000) + (ts.tv_nsec);
|
||||
#endif
|
||||
}
|
||||
|
||||
inline uint64_t get_tick_count()
|
||||
{
|
||||
return get_ns_count() / 1000000;
|
||||
}
|
||||
|
||||
inline bool get_gmt_time(time_t t, struct tm &tm)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return gmtime_s(&tm, &t);
|
||||
#else
|
||||
return gmtime_r(&t, &tm);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
|
@ -38,7 +38,7 @@
|
|||
#include "buffer.h"
|
||||
#include "misc_language.h"
|
||||
#include "syncobj.h"
|
||||
#include "misc_os_dependent.h"
|
||||
#include "time_helper.h"
|
||||
#include "int-util.h"
|
||||
|
||||
#include <random>
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#ifndef _PROFILE_TOOLS_H_
|
||||
#define _PROFILE_TOOLS_H_
|
||||
|
||||
#include "misc_os_dependent.h"
|
||||
#include "time_helper.h"
|
||||
|
||||
namespace epee
|
||||
{
|
||||
|
|
|
@ -28,83 +28,18 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
//#include <atltime.h>
|
||||
//#include <sqlext.h>
|
||||
#include <boost/date_time/posix_time/posix_time.hpp>
|
||||
#include <boost/date_time/local_time/local_time.hpp>
|
||||
#include <chrono>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
|
||||
#include "pragma_comp_defs.h"
|
||||
|
||||
namespace epee
|
||||
{
|
||||
namespace misc_utils
|
||||
{
|
||||
|
||||
#ifdef __ATLTIME_H__
|
||||
|
||||
inline
|
||||
bool get_time_t_from_ole_date(DATE src, time_t& res)
|
||||
{
|
||||
SYSTEMTIME st = {0};
|
||||
if(TRUE != ::VariantTimeToSystemTime(src, &st))
|
||||
return false;
|
||||
ATL::CTime ss(st);
|
||||
res = ss.GetTime();
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
inline
|
||||
std::string get_time_str(const time_t& time_)
|
||||
{
|
||||
|
||||
|
||||
char tmpbuf[200] = {0};
|
||||
tm* pt = NULL;
|
||||
PRAGMA_WARNING_PUSH
|
||||
PRAGMA_WARNING_DISABLE_VS(4996)
|
||||
pt = localtime(&time_);
|
||||
PRAGMA_WARNING_POP
|
||||
|
||||
if(pt)
|
||||
strftime( tmpbuf, 199, "%d.%m.%Y %H:%M:%S", pt );
|
||||
else
|
||||
{
|
||||
std::stringstream strs;
|
||||
strs << "[wrong_time: " << std::hex << time_ << "]";
|
||||
return strs.str();
|
||||
}
|
||||
return tmpbuf;
|
||||
}
|
||||
|
||||
inline
|
||||
std::string get_time_str_v2(const time_t& time_)
|
||||
{
|
||||
|
||||
char tmpbuf[200] = {0};
|
||||
tm* pt = NULL;
|
||||
PRAGMA_WARNING_PUSH
|
||||
PRAGMA_WARNING_DISABLE_VS(4996)
|
||||
pt = localtime(&time_);
|
||||
PRAGMA_WARNING_POP
|
||||
|
||||
if(pt)
|
||||
strftime( tmpbuf, 199, "%Y_%m_%d %H_%M_%S", pt );
|
||||
else
|
||||
{
|
||||
std::stringstream strs;
|
||||
strs << "[wrong_time: " << std::hex << time_ << "]";
|
||||
return strs.str();
|
||||
}
|
||||
return tmpbuf;
|
||||
}
|
||||
|
||||
inline
|
||||
std::string get_time_str_v3(const boost::posix_time::ptime& time_)
|
||||
{
|
||||
return boost::posix_time::to_simple_string(time_);
|
||||
}
|
||||
|
||||
|
||||
|
||||
inline std::string get_internet_time_str(const time_t& time_)
|
||||
{
|
||||
char tmpbuf[200] = {0};
|
||||
|
@ -135,25 +70,25 @@ PRAGMA_WARNING_POP
|
|||
return res;
|
||||
}
|
||||
|
||||
#ifdef __SQLEXT
|
||||
inline
|
||||
bool odbc_time_to_oledb_taime(const SQL_TIMESTAMP_STRUCT& odbc_timestamp, DATE& oledb_date)
|
||||
inline uint64_t get_ns_count()
|
||||
{
|
||||
|
||||
SYSTEMTIME st = {0};
|
||||
st.wYear = odbc_timestamp.year;
|
||||
st.wDay = odbc_timestamp.day;
|
||||
st.wHour = odbc_timestamp.hour ;
|
||||
st.wMilliseconds = (WORD)odbc_timestamp.fraction ;
|
||||
st.wMinute = odbc_timestamp.minute ;
|
||||
st.wMonth = odbc_timestamp.month ;
|
||||
st.wSecond = odbc_timestamp.second ;
|
||||
|
||||
if(TRUE != ::SystemTimeToVariantTime(&st, &oledb_date))
|
||||
return false;
|
||||
return true;
|
||||
typedef std::chrono::duration<uint64_t, std::nano> ns_duration;
|
||||
const ns_duration ns_since_epoch = std::chrono::steady_clock::now().time_since_epoch();
|
||||
return ns_since_epoch.count();
|
||||
}
|
||||
|
||||
inline uint64_t get_tick_count()
|
||||
{
|
||||
return get_ns_count() / 1000000;
|
||||
}
|
||||
|
||||
inline bool get_gmt_time(time_t t, struct tm &tm)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return gmtime_s(&tm, &t);
|
||||
#else
|
||||
return gmtime_r(&t, &tm);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
|
@ -40,7 +40,7 @@
|
|||
#include <boost/filesystem.hpp>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include "string_tools.h"
|
||||
#include "misc_os_dependent.h"
|
||||
#include "time_helper.h"
|
||||
#include "misc_log_ex.h"
|
||||
|
||||
#undef MONERO_DEFAULT_LOG_CATEGORY
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
// THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
|
||||
#include <vector>
|
||||
#include "misc_os_dependent.h"
|
||||
#include "time_helper.h"
|
||||
#include "perf_timer.h"
|
||||
|
||||
#undef MONERO_DEFAULT_LOG_CATEGORY
|
||||
|
|
|
@ -59,7 +59,7 @@
|
|||
#include "include_base_utils.h"
|
||||
#include "file_io_utils.h"
|
||||
#include "wipeable_string.h"
|
||||
#include "misc_os_dependent.h"
|
||||
#include "time_helper.h"
|
||||
using namespace epee;
|
||||
|
||||
#include "crypto/crypto.h"
|
||||
|
|
|
@ -30,6 +30,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <iomanip>
|
||||
#include <boost/uuid/uuid.hpp>
|
||||
#include <boost/serialization/version.hpp>
|
||||
#include "serialization/keyvalue_serialization.h"
|
||||
|
|
Loading…
Reference in New Issue