Stroika Library 3.0d16
 
Loading...
Searching...
No Matches
Sleep.h
Go to the documentation of this file.
1/*
2 * Copyright(c) Sophist Solutions, Inc. 1990-2025. All rights reserved
3 */
4#ifndef _Stroika_Foundation_Execution_Sleep_h_
5#define _Stroika_Foundation_Execution_Sleep_h_ 1
6
7#include "Stroika/Foundation/StroikaPreComp.h"
8
9#include "Stroika/Foundation/Common/Common.h"
12
13/**
14 * TODO
15 *
16 * \file
17 *
18 *
19 * @todo Should probably AMEND (though dangerous at this stage) behavior of Sleep and esp SleepUntil - so if interrupted (not throwing)
20 * with no 'sleep more seconds' arg- we re-sleep the balance. So interupots don't mess up how long we sleep.
21 *
22 */
23
25
26 /**
27 * The portable Sleep() function - will wait the given amount of time - blocking the calling thread.
28 * It CAN be interrupted (not talking about thread interrupt - e.g. POSIX signal). If interrupted, one overload will return the amount of time remaining, allowing
29 * easy re-sleeping. The other overload (/1) - will check for aborting, but otherwise keep sleeping
30 * through interrupts until the time has elapsed.
31 *
32 * @see SleepUntil
33 *
34 * Sleep\1: will restart sleeping to use up the full given sleep time, if interrupted (unless thread interruption causes throw)
35 * Sleep\2: may not use up the entire time given as argument, and if not, will place in remainingInSleep the time remaining.
36 *
37 * \par Example Usage
38 * \code
39 * Execution::Sleep (30ms);
40 * \endcode
41 *
42 * \note Sleep (0) will still yield the processor (so like std::thread::yield ())
43 *
44 * \pre seconds2Wait >= 0
45 *
46 * \post *remainingInSleep <= seconds2Wait
47 * \post *remainingInSleep >= 0
48 *
49 * \note \em Thread-Safety <a href="Thread-Safety.md#Internally-Synchronized-Thread-Safety">Internally-Synchronized-Thread-Safety</a>
50 *
51 * \note ***Cancelation Point***
52 *
53 * \note Very similar to std::this_thread::sleep_for () - except for the overload returning remaining amount, and cancelation support
54 *
55 */
56 void Sleep (Time::Duration seconds2Wait);
57 void Sleep (Time::Duration seconds2Wait, Time::DurationSeconds* remainingInSleep);
58
59 /**
60 * Wait until the tickCount is >= the given value.
61 *
62 * \par Example Usage
63 * \code
64 * Time::DurationSeconds startedAt = Time::GetTickCount ();
65 * do_something_dont_know_how_long_it_will_take();
66 * Execution::SleepUntil (1.0s + startedAt); // make sure do_something_dont_know_how_long_it_will_take () took at least one second
67 * \endcode
68 *
69 * @see Sleep ();
70 *
71 * \note ***Cancelation Point***
72 *
73 * \note Unlike Sleep () - this may or may not yield.
74 *
75 * \note SleepUntil restarts if interrupted, so if it returns, it will return after untilTickCount
76 *
77 * \note This may or may not end up calling Sleep(). It is not an error to call with a tickCount which has already passed: it just returns quickly, and may not yield.
78 *
79 * \note Very similar to std::this_thread::sleep_until () - except for the cancelation support
80 */
81 void SleepUntil (Time::TimePointSeconds untilTickCount);
82
83}
84
85/*
86 ********************************************************************************
87 ***************************** Implementation Details ***************************
88 ********************************************************************************
89 */
90#include "Sleep.inl"
91
92#endif /*_Stroika_Foundation_Execution_Sleep_h_*/
void Sleep(Time::Duration seconds2Wait)
Definition Sleep.cpp:18
void SleepUntil(Time::TimePointSeconds untilTickCount)
Definition Sleep.inl:91