DUDS
Distributed Update of Data from Something
YieldingWait.hpp
Go to the documentation of this file.
1 /*
2  * This file is part of the DUDS project. It is subject to the BSD-style
3  * license terms in the LICENSE file found in the top-level directory of this
4  * distribution and at https://github.com/jjackowski/duds/blob/master/LICENSE.
5  * No part of DUDS, including this file, may be copied, modified, propagated,
6  * or distributed except according to the terms contained in the LICENSE file.
7  *
8  * Copyright (C) 2018 Jeff Jackowski
9  */
10 
11 #include <thread>
12 #include <chrono>
13 
14 namespace duds { namespace general {
15 
27 template <class Duration>
28 void YieldingWait(Duration duration) {
29  auto when = std::chrono::high_resolution_clock::now() + duration;
30  do {
31  std::this_thread::yield();
32  } while (std::chrono::high_resolution_clock::now() < when);
33 }
34 
45 inline void YieldingWait(int nano) {
46  YieldingWait(std::chrono::nanoseconds(nano));
47 }
48 
49 } }
void YieldingWait(Duration duration)
Waits for a minumum period of time by calling std::this_thread::yield() in a loop.