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.
11 // can define ADD_MOVE_SEMANTICS, although not fully debugged and tested
14 namespace chrono = std::chrono;
17 #ifdef ADD_MOVE_SEMANTICS
18 crimson::RunEvery::RunEvery()
24 crimson::RunEvery& crimson::RunEvery::operator=(crimson::RunEvery&& other)
26 // finish run every thread
36 // transfer info over from previous thread
37 finishing.store(other.finishing);
38 wait_period = other.wait_period;
41 // finish other thread
42 other.finishing.store(true);
43 other.cv.notify_one();
46 thd = std::thread(&RunEvery::run, this);
53 crimson::RunEvery::~RunEvery() {
58 void crimson::RunEvery::join() {
61 if (finishing) return;
69 void crimson::RunEvery::run() {
72 TimePoint until = chrono::steady_clock::now() + wait_period;
73 while (!finishing && chrono::steady_clock::now() < until) {
74 cv.wait_until(l, until);