summaryrefslogtreecommitdiff
path: root/src/periodic.h
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-03-20 18:51:03 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-03-20 18:51:03 +0200
commit5dfb890cf841579edaeb2633025db218e86f45c2 (patch)
treea6937d904579b8d7051cf033e03e99464d298c98 /src/periodic.h
parentaa70507d43d17ca2c426acd6bf91548fe267ac19 (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.h16
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. */
26iDeclareType(Periodic) 26iDeclareType(Periodic)
27iDeclareType(Thread) 27iDeclareType(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. */
30struct Impl_Periodic { 30struct 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
38void init_Periodic (iPeriodic *); 36void init_Periodic (iPeriodic *);
39void deinit_Periodic (iPeriodic *); 37void deinit_Periodic (iPeriodic *);
40 38
41void add_Periodic (iPeriodic *, iAny *context, const char *command); 39iLocalDef iBool isEmpty_Periodic(const iPeriodic *d) {
42void remove_Periodic (iPeriodic *, iAny *context); 40 return isEmpty_SortedArray(&d->commands);
41}
42
43void add_Periodic (iPeriodic *, iAny *context, const char *command);
44void remove_Periodic (iPeriodic *, iAny *context);
45
46iBool postCommands_Periodic (iPeriodic *);