diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-03-20 18:51:03 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-03-20 18:51:03 +0200 |
commit | 5dfb890cf841579edaeb2633025db218e86f45c2 (patch) | |
tree | a6937d904579b8d7051cf033e03e99464d298c98 /src/periodic.h | |
parent | aa70507d43d17ca2c426acd6bf91548fe267ac19 (diff) |
App: Periodic commands without timers/threads
Now the periodic commands get posted on the main thread at intervals, and the event loop cooperates by not sleeping if there are periodic commands pending.
The macOS animation hangup seems to be unrelated, though — perhaps some internal SDL/Metal machinery related to app refresh stopping for a while?
Diffstat (limited to 'src/periodic.h')
-rw-r--r-- | src/periodic.h | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/periodic.h b/src/periodic.h index c643a2fe..db90b848 100644 --- a/src/periodic.h +++ b/src/periodic.h | |||
@@ -26,17 +26,21 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ | |||
26 | iDeclareType(Periodic) | 26 | iDeclareType(Periodic) |
27 | iDeclareType(Thread) | 27 | iDeclareType(Thread) |
28 | 28 | ||
29 | /* Animation utility. Not per frame but several times per second. */ | 29 | /* Animation utility. Not per frame but several times per second. Thread safe. */ |
30 | struct Impl_Periodic { | 30 | struct Impl_Periodic { |
31 | iMutex * mutex; | 31 | iMutex * mutex; |
32 | iSortedArray commands; | 32 | iSortedArray commands; |
33 | iCondition haveCommands; | 33 | uint32_t lastPostTime; |
34 | iThread * thread; | ||
35 | iAtomicInt isStopping; | ||
36 | }; | 34 | }; |
37 | 35 | ||
38 | void init_Periodic (iPeriodic *); | 36 | void init_Periodic (iPeriodic *); |
39 | void deinit_Periodic (iPeriodic *); | 37 | void deinit_Periodic (iPeriodic *); |
40 | 38 | ||
41 | void add_Periodic (iPeriodic *, iAny *context, const char *command); | 39 | iLocalDef iBool isEmpty_Periodic(const iPeriodic *d) { |
42 | void remove_Periodic (iPeriodic *, iAny *context); | 40 | return isEmpty_SortedArray(&d->commands); |
41 | } | ||
42 | |||
43 | void add_Periodic (iPeriodic *, iAny *context, const char *command); | ||
44 | void remove_Periodic (iPeriodic *, iAny *context); | ||
45 | |||
46 | iBool postCommands_Periodic (iPeriodic *); | ||