From 5dfb890cf841579edaeb2633025db218e86f45c2 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Sat, 20 Mar 2021 18:51:03 +0200 Subject: App: Periodic commands without timers/threads MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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? --- src/periodic.h | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/periodic.h') 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. */ iDeclareType(Periodic) iDeclareType(Thread) -/* Animation utility. Not per frame but several times per second. */ +/* Animation utility. Not per frame but several times per second. Thread safe. */ struct Impl_Periodic { iMutex * mutex; iSortedArray commands; - iCondition haveCommands; - iThread * thread; - iAtomicInt isStopping; + uint32_t lastPostTime; }; void init_Periodic (iPeriodic *); void deinit_Periodic (iPeriodic *); -void add_Periodic (iPeriodic *, iAny *context, const char *command); -void remove_Periodic (iPeriodic *, iAny *context); +iLocalDef iBool isEmpty_Periodic(const iPeriodic *d) { + return isEmpty_SortedArray(&d->commands); +} + +void add_Periodic (iPeriodic *, iAny *context, const char *command); +void remove_Periodic (iPeriodic *, iAny *context); + +iBool postCommands_Periodic (iPeriodic *); -- cgit v1.2.3