From 1a98ef3985e2f287cf3c78e0ce7ac40a2ca44217 Mon Sep 17 00:00:00 2001 From: Seungkeun Lee Date: Thu, 30 Nov 2017 11:51:21 +0900 Subject: [PATCH] [ElmSharp] Fix EcoreMainloop crash issue in multi thread - EcoreMainLoop.Post allow to call in worker thread - Dictionary.Add was used in Post and it didn't support multi-thread and did not protected by lock - So, Replace to ConcurrentDictionary Change-Id: I0a964d49317380ba81751c4d4b1cc0484f7a39c5 --- src/ElmSharp/ElmSharp/EcoreMainloop.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) mode change 100755 => 100644 src/ElmSharp/ElmSharp/EcoreMainloop.cs diff --git a/src/ElmSharp/ElmSharp/EcoreMainloop.cs b/src/ElmSharp/ElmSharp/EcoreMainloop.cs old mode 100755 new mode 100644 index b15658f..60202fa --- a/src/ElmSharp/ElmSharp/EcoreMainloop.cs +++ b/src/ElmSharp/ElmSharp/EcoreMainloop.cs @@ -15,7 +15,7 @@ */ using System; -using System.Collections.Generic; +using System.Collections.Concurrent; namespace ElmSharp { @@ -25,7 +25,8 @@ namespace ElmSharp /// preview public static class EcoreMainloop { - static readonly Dictionary> _taskMap = new Dictionary>(); + + static readonly ConcurrentDictionary> _taskMap = new ConcurrentDictionary>(); static readonly Object _taskLock = new Object(); static int _newTaskId = 0; @@ -117,7 +118,8 @@ namespace ElmSharp public static void RemoveTimer(IntPtr id) { int taskId = (int)Interop.Ecore.ecore_timer_del(id); - _taskMap.Remove(taskId); + Func unused; + _taskMap.TryRemove(taskId, out unused); } static int RegistHandler(Func task) @@ -140,11 +142,14 @@ namespace ElmSharp bool result = false; if (userAction != null) + { result = userAction(); + } - if (result == false) - _taskMap.Remove(task_id); - + if (!result) + { + _taskMap.TryRemove(task_id, out userAction); + } return result; } return false; -- 2.7.4