2018-05-30 21:34:38 +02:00
|
|
|
/*******************************************************************************
|
|
|
|
* libretroshare/src/util: rstime.h *
|
|
|
|
* *
|
|
|
|
* libretroshare: retroshare core library *
|
|
|
|
* *
|
|
|
|
* Copyright 2013-2013 by Cyril Soler <csoler@users.sourceforge.net> *
|
|
|
|
* *
|
|
|
|
* This program is free software: you can redistribute it and/or modify *
|
|
|
|
* it under the terms of the GNU Lesser General Public License as *
|
|
|
|
* published by the Free Software Foundation, either version 3 of the *
|
|
|
|
* License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program 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 Lesser General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU Lesser General Public License *
|
|
|
|
* along with this program. If not, see <https://www.gnu.org/licenses/>. *
|
|
|
|
* *
|
|
|
|
*******************************************************************************/
|
2018-10-07 01:34:05 +02:00
|
|
|
#pragma once
|
|
|
|
|
2015-08-11 23:19:37 +02:00
|
|
|
#include <string>
|
2018-10-12 13:52:19 +02:00
|
|
|
#ifdef WINDOWS_SYS
|
|
|
|
#include <stdint.h>
|
|
|
|
#else
|
2018-10-07 01:34:05 +02:00
|
|
|
#include <cstdint>
|
2018-10-12 13:52:19 +02:00
|
|
|
#endif
|
2018-10-07 01:34:05 +02:00
|
|
|
#include <ctime> // Added for comfort of users of this util header
|
2019-02-13 17:07:03 -03:00
|
|
|
#include "util/rsdeprecate.h"
|
2018-10-07 01:34:05 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Safer alternative to time_t.
|
|
|
|
* As time_t have not same lenght accross platforms, even though representation
|
|
|
|
* is not guaranted to be the same but we found it being number of seconds since
|
|
|
|
* the epoch for time points in all platforms we could test, or plain seconds
|
|
|
|
* for intervals.
|
|
|
|
* Still in some platforms it's 32bit long and in other 64bit long.
|
|
|
|
* To avoid uncompatibility due to different serialzation format use this
|
|
|
|
* reasonably safe alternative instead.
|
|
|
|
*/
|
|
|
|
typedef int64_t rstime_t;
|
2013-10-20 13:29:24 +00:00
|
|
|
|
2018-10-07 01:34:05 +02:00
|
|
|
// Do we really need this? Our names have rs prefix to avoid pollution already!
|
2018-01-27 20:22:31 +01:00
|
|
|
namespace rstime {
|
|
|
|
|
2019-04-12 02:53:39 +02:00
|
|
|
/**
|
|
|
|
* @deprecated { std::this_thread::sleep_for or
|
|
|
|
* std::this_thread::sleep_until instead }
|
|
|
|
* @brief This is a cross-system definition of usleep, which accepts any
|
|
|
|
* 32 bits number of micro-seconds.
|
|
|
|
*/
|
|
|
|
RS_DEPRECATED_FOR("std::this_thread::sleep_for")
|
|
|
|
int rs_usleep(uint32_t micro_seconds);
|
2018-01-27 20:22:31 +01:00
|
|
|
|
|
|
|
/* Use this class to measure and display time duration of a given environment:
|
|
|
|
|
|
|
|
{
|
|
|
|
RsScopeTimer timer("callToMeasure()") ;
|
|
|
|
|
|
|
|
callToMeasure() ;
|
|
|
|
}
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
class RsScopeTimer
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
RsScopeTimer(const std::string& name);
|
|
|
|
~RsScopeTimer();
|
|
|
|
|
|
|
|
void start();
|
|
|
|
double duration();
|
2013-10-19 20:54:42 +00:00
|
|
|
|
2018-01-27 20:22:31 +01:00
|
|
|
static double currentTime();
|
2013-10-20 13:29:24 +00:00
|
|
|
|
2018-01-27 20:22:31 +01:00
|
|
|
private:
|
|
|
|
std::string _name ;
|
|
|
|
double _seconds ;
|
|
|
|
};
|
2013-10-19 20:54:42 +00:00
|
|
|
|
2018-01-27 20:22:31 +01:00
|
|
|
}
|