Fix for thread-safe issue
authorSeungkeun Lee <sngn.lee@samsung.com>
Wed, 21 Dec 2016 04:32:02 +0000 (13:32 +0900)
committerHwanKyu Jhun <h.jhun@samsung.com>
Thu, 22 Dec 2016 04:30:16 +0000 (20:30 -0800)
 - TizenSynchronizationContext could be called by worker thread
 - but underlying Dictionary class was not support thread-safe
 - Change to ConcurrentDictionary

Change-Id: I73bfb6cab5de307cff185b39a44705bf79dabe1f

Tizen.Applications/Tizen.Applications/TizenSynchronizationContext.cs [changed mode: 0755->0644]
packaging/csapi-application.spec

old mode 100755 (executable)
new mode 100644 (file)
index 9644eca..dcfb4c8
@@ -15,7 +15,7 @@
  */
 
 using System;
-using System.Collections.Generic;
+using System.Collections.Concurrent;
 using System.Threading;
 
 namespace Tizen.Applications
@@ -28,7 +28,7 @@ namespace Tizen.Applications
     {
         private readonly Interop.Glib.GSourceFunc _wrapperHandler;
         private readonly Object _transactionLock = new Object();
-        private readonly Dictionary<int, Action> _handlerMap = new Dictionary<int, Action>();
+        private readonly ConcurrentDictionary<int, Action> _handlerMap = new ConcurrentDictionary<int, Action>();
         private int _transactionId = 0;
 
         /// <summary>
@@ -109,7 +109,7 @@ namespace Tizen.Applications
             {
                 id = _transactionId++;
             }
-            _handlerMap.Add(id, action);
+            _handlerMap.TryAdd(id, action);
             Interop.Glib.IdleAdd(_wrapperHandler, (IntPtr)id);
         }
 
@@ -118,8 +118,9 @@ namespace Tizen.Applications
             int key = (int)userData;
             if (_handlerMap.ContainsKey(key))
             {
-                _handlerMap[key]();
-                _handlerMap.Remove(key);
+                Action action;
+                _handlerMap.TryRemove(key, out action);
+                action?.Invoke();
             }
             return false;
         }
index fb12fe6..6fcb501 100755 (executable)
@@ -1,6 +1,6 @@
 Name:       csapi-application
 Summary:    Tizen Application API for C#
-Version:    1.0.2
+Version:    1.0.3
 Release:    1
 Group:      Development/Libraries
 License:    Apache-2.0
@@ -41,4 +41,4 @@ done
 %files
 %manifest %{name}.manifest
 %license LICENSE
-%attr(644,root,root) %{dotnet_assembly_files}
\ No newline at end of file
+%attr(644,root,root) %{dotnet_assembly_files}