fw4spl
wait.hpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2018.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #pragma once
8 
9 #include <fwCore/TimeStamp.hpp>
10 
11 #include <chrono>
12 #include <thread>
13 
14 // Wait at worst 1s for a given condition
15 #define fwTestWaitMacro(cond) \
16  ::fwCore::TimeStamp BOOST_PP_CAT(timeStamp, __LINE__); \
17  BOOST_PP_CAT(timeStamp, __LINE__).setLifePeriod(1000); \
18  BOOST_PP_CAT(timeStamp, __LINE__).modified(); \
19  while(!(cond) && !BOOST_PP_CAT(timeStamp, __LINE__).periodExpired()) \
20  { \
21  std::this_thread::sleep_for( std::chrono::milliseconds(10)); \
22  }