X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fceph%2Fsrc%2Fdmclock%2Fsupport%2Fsrc%2Frun_every.cc;fp=src%2Fceph%2Fsrc%2Fdmclock%2Fsupport%2Fsrc%2Frun_every.cc;h=0000000000000000000000000000000000000000;hb=7da45d65be36d36b880cc55c5036e96c24b53f00;hp=cab414109a9dc6fcc648fff7873d432961d29cdb;hpb=691462d09d0987b47e112d6ee8740375df3c51b2;p=stor4nfv.git diff --git a/src/ceph/src/dmclock/support/src/run_every.cc b/src/ceph/src/dmclock/support/src/run_every.cc deleted file mode 100644 index cab4141..0000000 --- a/src/ceph/src/dmclock/support/src/run_every.cc +++ /dev/null @@ -1,80 +0,0 @@ -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab -/* - * Copyright (C) 2017 Red Hat Inc. - */ - - -#include "run_every.h" - - -// can define ADD_MOVE_SEMANTICS, although not fully debugged and tested - - -namespace chrono = std::chrono; - - -#ifdef ADD_MOVE_SEMANTICS -crimson::RunEvery::RunEvery() -{ - // empty -} - - -crimson::RunEvery& crimson::RunEvery::operator=(crimson::RunEvery&& other) -{ - // finish run every thread - { - Guard g(mtx); - finishing = true; - cv.notify_one(); - } - if (thd.joinable()) { - thd.join(); - } - - // transfer info over from previous thread - finishing.store(other.finishing); - wait_period = other.wait_period; - body = other.body; - - // finish other thread - other.finishing.store(true); - other.cv.notify_one(); - - // start this thread - thd = std::thread(&RunEvery::run, this); - - return *this; -} -#endif - - -crimson::RunEvery::~RunEvery() { - join(); -} - - -void crimson::RunEvery::join() { - { - Guard l(mtx); - if (finishing) return; - finishing = true; - cv.notify_all(); - } - thd.join(); -} - - -void crimson::RunEvery::run() { - Lock l(mtx); - while(!finishing) { - TimePoint until = chrono::steady_clock::now() + wait_period; - while (!finishing && chrono::steady_clock::now() < until) { - cv.wait_until(l, until); - } - if (!finishing) { - body(); - } - } -}