]>
git.proxmox.com Git - ceph.git/blob - ceph/src/dmclock/support/src/run_every.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Copyright (C) 2017 Red Hat Inc.
12 #include <condition_variable>
17 using std::chrono::duration_cast
;
18 using std::chrono::milliseconds
;
20 // runs a given simple function object waiting wait_period
21 // milliseconds between; the destructor stops the other thread
24 using Lock
= std::unique_lock
<std::mutex
>;
25 using Guard
= std::lock_guard
<std::mutex
>;
26 using TimePoint
= std::chrono::steady_clock::time_point
;
28 bool finishing
= false;
29 std::chrono::milliseconds wait_period
;
30 std::function
<void()> body
;
32 std::condition_variable cv
;
34 // put threads last so all other variables are initialized first
40 #ifdef ADD_MOVE_SEMANTICS
45 RunEvery(D _wait_period
,
46 std::function
<void()> _body
) :
47 wait_period(duration_cast
<milliseconds
>(_wait_period
)),
50 thd
= std::thread(&RunEvery::run
, this);
53 RunEvery(const RunEvery
& other
) = delete;
54 RunEvery
& operator=(const RunEvery
& other
) = delete;
55 RunEvery(RunEvery
&& other
) = delete;
56 #ifdef ADD_MOVE_SEMANTICS
57 RunEvery
& operator=(RunEvery
&& other
);
59 RunEvery
& operator=(RunEvery
&& other
) = delete;