PMDK C++ bindings 1.13.0
This is the C++ bindings documentation for PMDK's libpmemobj.
Loading...
Searching...
No Matches
conversions.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSD-3-Clause
2/* Copyright 2016-2018, Intel Corporation */
3
9#ifndef LIBPMEMOBJ_CPP_CONVERSIONS_HPP
10#define LIBPMEMOBJ_CPP_CONVERSIONS_HPP
11
12#include <chrono>
13#include <ctime>
14
15namespace pmem
16{
17
18namespace detail
19{
20
28template <typename Clock, typename Duration = typename Clock::duration>
29timespec
30timepoint_to_timespec(const std::chrono::time_point<Clock, Duration> &timepoint)
31{
32 timespec ts;
33 auto rel_duration = timepoint.time_since_epoch();
34 const auto sec =
35 std::chrono::duration_cast<std::chrono::seconds>(rel_duration);
36
37 ts.tv_sec = sec.count();
38 ts.tv_nsec = static_cast<long>(
39 std::chrono::duration_cast<std::chrono::nanoseconds>(
40 rel_duration - sec)
41 .count());
42
43 return ts;
44}
45
46} /* namespace detail */
47
48} /* namespace pmem */
49
50#endif /* LIBPMEMOBJ_CPP_CONVERSIONS_HPP */
timespec timepoint_to_timespec(const std::chrono::time_point< Clock, Duration > &timepoint)
Convert std::chrono::time_point to posix timespec.
Definition: conversions.hpp:30
Persistent memory namespace.
Definition: allocation_flag.hpp:15