[MediaContent] Fixed possible deadlock issues of async methods. 74/153674/1
authorcoderhyme <jhyo.kim@samsung.com>
Fri, 29 Sep 2017 05:53:10 +0000 (14:53 +0900)
committercoderhyme <jhyo.kim@samsung.com>
Fri, 29 Sep 2017 05:53:10 +0000 (14:53 +0900)
It could occur when the continuations run synchronously, because the native implementaion holds mutex when it calls the callback.
In such situation if any related async method is called, it is going to be blocked.

Thus we need to force the continuations to run asyncronously.

Change-Id: I5aa12733cde352de65bc722ecebd8c6b3f92d55e
Signed-off-by: coderhyme <jhyo.kim@samsung.com>
src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaDatabase.cs
src/Tizen.Content.MediaContent/Tizen.Content.MediaContent/MediaInfoCommand.cs

index 8474364..72031a5 100644 (file)
@@ -354,7 +354,7 @@ namespace Tizen.Content.MediaContent
 
         private async Task ScanFolderAsyncCore(string folderPath, bool recursive, CancellationToken cancellationToken)
         {
-            var tcs = new TaskCompletionSource<bool>();
+            var tcs = new TaskCompletionSource<bool>(TaskContinuationOptions.RunContinuationsAsynchronously);
 
             using (var cbKeeper = ObjectKeeper.Get(GetScanCompletedCallback(tcs, cancellationToken)))
             using (RegisterCancellationAction(tcs, folderPath, cancellationToken))
index 7eb2be4..f0a5fb3 100644 (file)
@@ -602,7 +602,7 @@ namespace Tizen.Content.MediaContent
             ValidatePaths(paths);
 
             var pathArray = paths.ToArray();
-            var tcs = new TaskCompletionSource<bool>();
+            var tcs = new TaskCompletionSource<bool>(TaskContinuationOptions.RunContinuationsAsynchronously);
 
             Interop.MediaInfo.InsertCompletedCallback callback = (error, _) =>
             {
@@ -658,7 +658,7 @@ namespace Tizen.Content.MediaContent
 
             ValidatePaths(paths);
 
-            var tcs = new TaskCompletionSource<bool>();
+            var tcs = new TaskCompletionSource<bool>(TaskContinuationOptions.RunContinuationsAsynchronously);
             string[] pathArray = paths.ToArray();
 
             Interop.MediaInfo.InsertBurstShotCompletedCallback callback = (error, _) =>