[Tizen.Applications.DataControl] Fix issue for multithreads (#171) 4.0.1.14116
authorkilig <inkyun.kil@samsung.com>
Tue, 20 Mar 2018 09:22:47 +0000 (18:22 +0900)
committersemun-lee <35090067+semun-lee@users.noreply.github.com>
Tue, 20 Mar 2018 09:22:47 +0000 (18:22 +0900)
- Add locking mutex codes for register/unregister callback
- Check key if it is contained in dtor

Signed-off-by: Inkyun Kil <inkyun.kil@samsung.com>
src/Tizen.Applications.DataControl/Tizen.Applications.DataControl/Consumer.cs

index 745b8c2..22ea550 100755 (executable)
@@ -435,6 +435,12 @@ namespace Tizen.Applications.DataControl
             {
                 int count;
 
+                if (!_reqProviderList.ContainsKey(providerId))
+                {
+                    Log.Error(LogTag, "The provider id is not contained : " + providerId);
+                    return;
+                }
+
                 _reqProviderList[providerId]--;
                 count = _reqProviderList[providerId];
                 if (count <= 0)
@@ -872,7 +878,9 @@ namespace Tizen.Applications.DataControl
 
             Interop.DataControl.DataControlSetProviderId(_handle, providerId);
             Interop.DataControl.DataControlSetDataId(_handle, dataId);
+            _lock.WaitOne();
             CallbackManager.RegisterCallback(_handle, providerId);
+            _lock.ReleaseMutex();
             _dataID = dataId;
             _providerID = providerId;
         }
@@ -994,7 +1002,9 @@ namespace Tizen.Applications.DataControl
                     Interop.DataControl.RemoveDataChangeCallback(_handle, _changeCallbackID);
                 }
 
+                _lock.WaitOne();
                 CallbackManager.UnregisterCallback(_handle, _providerID);
+                _lock.ReleaseMutex();
                 _handle.Dispose();
                 _disposed = true;
             }