Skip to content

Commit fa3b3cb

Browse files
author
MacroFake
committed
Expose underlying clock in CThreadInterrupt
Overloading sleep_for is not needed, as * seconds and minutes can be converted to milliseconds by the compiler, not needing a duration_cast * std::condition_variable::wait_for will convert milliseconds to the duration type of the underlying clock So simply expose the clock.
1 parent 1d89fc6 commit fa3b3cb

File tree

3 files changed

+4
-14
lines changed

3 files changed

+4
-14
lines changed

ci/test/06_script_b.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ if [ "${RUN_TIDY}" = "true" ]; then
4747
" src/rpc/fees.cpp"\
4848
" src/rpc/signmessage.cpp"\
4949
" src/test/fuzz/txorphan.cpp"\
50+
" src/threadinterrupt.cpp"\
5051
" src/util/bip32.cpp"\
5152
" src/util/bytevectorhash.cpp"\
5253
" src/util/error.cpp"\

src/threadinterrupt.cpp

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,8 @@ void CThreadInterrupt::operator()()
2828
cond.notify_all();
2929
}
3030

31-
bool CThreadInterrupt::sleep_for(std::chrono::milliseconds rel_time)
31+
bool CThreadInterrupt::sleep_for(Clock::duration rel_time)
3232
{
3333
WAIT_LOCK(mut, lock);
3434
return !cond.wait_for(lock, rel_time, [this]() { return flag.load(std::memory_order_acquire); });
3535
}
36-
37-
bool CThreadInterrupt::sleep_for(std::chrono::seconds rel_time)
38-
{
39-
return sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(rel_time));
40-
}
41-
42-
bool CThreadInterrupt::sleep_for(std::chrono::minutes rel_time)
43-
{
44-
return sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(rel_time));
45-
}

src/threadinterrupt.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,12 @@
1919
class CThreadInterrupt
2020
{
2121
public:
22+
using Clock = std::chrono::steady_clock;
2223
CThreadInterrupt();
2324
explicit operator bool() const;
2425
void operator()() EXCLUSIVE_LOCKS_REQUIRED(!mut);
2526
void reset();
26-
bool sleep_for(std::chrono::milliseconds rel_time) EXCLUSIVE_LOCKS_REQUIRED(!mut);
27-
bool sleep_for(std::chrono::seconds rel_time) EXCLUSIVE_LOCKS_REQUIRED(!mut);
28-
bool sleep_for(std::chrono::minutes rel_time) EXCLUSIVE_LOCKS_REQUIRED(!mut);
27+
bool sleep_for(Clock::duration rel_time) EXCLUSIVE_LOCKS_REQUIRED(!mut);
2928

3029
private:
3130
std::condition_variable cond;

0 commit comments

Comments
 (0)