mirror of
https://github.com/boostorg/interprocess.git
synced 2026-01-19 04:12:13 +00:00
Use unsigned long long microseconds instead of floating point in get_current_process_creation_time() to avoid rounding errors.
This commit is contained in:
@@ -47,8 +47,10 @@ inline void get_pid_creation_time_str(std::string &s)
|
||||
{
|
||||
std::stringstream stream;
|
||||
stream << get_current_process_id() << '_';
|
||||
stream.precision(6);
|
||||
stream << std::fixed << get_current_process_creation_time();
|
||||
const unsigned long long total_microsecs = get_current_process_creation_time();
|
||||
const unsigned long secs = static_cast<unsigned long>(total_microsecs/1000000ul);
|
||||
const unsigned long usecs = static_cast<unsigned long>(total_microsecs%1000000ul);
|
||||
stream << secs << '.' << usecs;
|
||||
s = stream.str();
|
||||
}
|
||||
|
||||
|
||||
@@ -220,17 +220,18 @@ inline OS_systemwide_thread_id_t get_invalid_systemwide_thread_id()
|
||||
return get_invalid_thread_id();
|
||||
}
|
||||
|
||||
inline long double get_current_process_creation_time()
|
||||
inline unsigned long long get_current_process_creation_time()
|
||||
{
|
||||
winapi::interprocess_filetime CreationTime, ExitTime, KernelTime, UserTime;
|
||||
|
||||
winapi::get_process_times
|
||||
( winapi::get_current_process(), &CreationTime, &ExitTime, &KernelTime, &UserTime);
|
||||
|
||||
typedef long double ldouble_t;
|
||||
const ldouble_t resolution = (100.0l/1000000000.0l);
|
||||
return CreationTime.dwHighDateTime*(ldouble_t(1u<<31u)*2.0l*resolution) +
|
||||
CreationTime.dwLowDateTime*resolution;
|
||||
unsigned long long microsecs = CreationTime.dwHighDateTime;
|
||||
microsecs <<= 32u;
|
||||
microsecs |= CreationTime.dwLowDateTime;
|
||||
microsecs /= 10u;
|
||||
return microsecs;
|
||||
}
|
||||
|
||||
inline unsigned int get_num_cores()
|
||||
@@ -476,8 +477,8 @@ inline OS_systemwide_thread_id_t get_invalid_systemwide_thread_id()
|
||||
return OS_systemwide_thread_id_t(get_invalid_process_id(), get_invalid_thread_id());
|
||||
}
|
||||
|
||||
inline long double get_current_process_creation_time()
|
||||
{ return 0.0L; }
|
||||
inline unsigned long long get_current_process_creation_time()
|
||||
{ return 0u; }
|
||||
|
||||
inline unsigned int get_num_cores()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user