From 5268fb9f7e1bca4b0fc496ff115c253aea724e49 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Tue, 24 Nov 2020 22:11:11 +0200 Subject: Fixed threading issues and data races The most serious problem was that GmRequest's response body was being accessed while the TlsRequest thread was modifying it. Now the response must always be locked before accessing elsewhere. There were also inefficient data updates in the media players. --- src/media.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/media.c') diff --git a/src/media.c b/src/media.c index cd3dfb82..8bd635a5 100644 --- a/src/media.c +++ b/src/media.c @@ -154,12 +154,13 @@ void clear_Media(iMedia *d) { clear_PtrArray(&d->audio); } -void setData_Media(iMedia *d, iGmLinkId linkId, const iString *mime, const iBlock *data, - int flags) { +iBool setData_Media(iMedia *d, iGmLinkId linkId, const iString *mime, const iBlock *data, + int flags) { const iBool isPartial = (flags & partialData_MediaFlag) != 0; const iBool allowHide = (flags & allowHide_MediaFlag) != 0; const iBool isDeleting = (!mime || !data); - iMediaId existing = findLinkImage_Media(d, linkId); + iMediaId existing = findLinkImage_Media(d, linkId); + iBool isNew = iFalse; if (existing) { iGmImage *img; if (isDeleting) { @@ -205,6 +206,7 @@ void setData_Media(iMedia *d, iGmLinkId linkId, const iString *mime, const iBloc if (!isPartial) { makeTexture_GmImage(img); } + isNew = iTrue; } else if (startsWith_String(mime, "audio/")) { iGmAudio *audio = new_GmAudio(); @@ -219,8 +221,10 @@ void setData_Media(iMedia *d, iGmLinkId linkId, const iString *mime, const iBloc /* Start playing right away. */ start_Player(audio->player); postCommandf_App("media.player.started player:%p", audio->player); + isNew = iTrue; } } + return isNew; } iMediaId findLinkImage_Media(const iMedia *d, iGmLinkId linkId) { -- cgit v1.2.3