Skip to content

Commit abf59d2

Browse files
committed
Fix to_timespec
1 parent 1e730a5 commit abf59d2

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

src/rpp/shm_mutex.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,21 @@
55
#include <condition_variable>
66

77
namespace rpp {
8-
inline timespec to_timespec(const std::chrono::system_clock::time_point& tp);
8+
9+
template<class Clock, class Duration>
10+
inline timespec to_timespec(const std::chrono::time_point<Clock, Duration>& tp)
11+
{
12+
using namespace std::chrono;
13+
14+
// Get duration since the system_clock epoch, in nanoseconds
15+
auto d = tp.time_since_epoch();
16+
auto ns = duration_cast<nanoseconds>(d).count();
17+
18+
timespec ts;
19+
ts.tv_sec = ns / 1'000'000'000;
20+
ts.tv_nsec = ns % 1'000'000'000;
21+
return ts;
22+
}
923

1024
class shm_mutex
1125
{
@@ -115,18 +129,4 @@ namespace rpp {
115129
native_handle_type native_handle() noexcept { return &handle; }
116130
};
117131

118-
inline timespec to_timespec(const std::chrono::system_clock::time_point& tp)
119-
{
120-
using namespace std::chrono;
121-
122-
// Get duration since the system_clock epoch, in nanoseconds
123-
auto d = tp.time_since_epoch();
124-
auto ns = duration_cast<nanoseconds>(d).count();
125-
126-
timespec ts;
127-
ts.tv_sec = ns / 1'000'000'000;
128-
ts.tv_nsec = ns % 1'000'000'000;
129-
return ts;
130-
}
131-
132132
} // namespace rpp

0 commit comments

Comments
 (0)