PMDK C++ bindings  1.11.1
This is the C++ bindings documentation for PMDK's libpmemobj.
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 
15 namespace pmem
16 {
17 
18 namespace detail
19 {
20 
28 template <typename Clock, typename Duration = typename Clock::duration>
29 timespec
30 timepoint_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 */
pmem::detail::timepoint_to_timespec
timespec timepoint_to_timespec(const std::chrono::time_point< Clock, Duration > &timepoint)
Convert std::chrono::time_point to posix timespec.
Definition: conversions.hpp:30
pmem
Persistent memory namespace.
Definition: allocation_flag.hpp:15