Fix lockup issue occurred while stress test for filesystem
authorJihye Kang <jye.kang@samsung.com>
Tue, 9 Apr 2013 15:57:54 +0000 (00:57 +0900)
committerGerrit Code Review <gerrit2@kim11>
Thu, 11 Apr 2013 08:17:52 +0000 (17:17 +0900)
[Title] Fix lockup issue occurred while stress test for filesystem
[Issue#] N/A
[Problem] Lockup occurs while calling writer.write() stressfully
[Cause] ecore_pipe_write() is blocked because PIPE_BUF is full with O_NONBLOCK disabled for waiting the pipe is ready to write.
But pipe cannot be consumed because main thread is blocked because ecore_pipe_write() is blocked.
[Solution] dispatchFunctionsFromMainThread(), called by registered Ecore_Pipe_Cb for the pipe, consume functionQueue as many as possible until maxRunLoopSuspensionTime is reached.
It means ecore_pipe_write() does not needed to be called when waiting for pipe is read. - write:read does not need to be 1:1 call.
So add flag for check whether scheduled request waiting for read exists or not.

Change-Id: I58a2724c1eb33c1565a88844cc87e33ee576a6d4

Source/WTF/wtf/Platform.h
Source/WTF/wtf/efl/MainThreadEfl.cpp

index a661e20..837e27e 100644 (file)
@@ -797,6 +797,8 @@ com) : Patch to do not adjust cover rect as fixed pixel size*/
 
 #define ENABLE_TIZEN_GET_EXTERNAL_RESOURCES_IN_MHTML_FROM_NETWORK 1 /* Praveen(praveen.ks@samsung.com) : Allow external resources in MHTML file to be fetched from network rather than failing them */
 
+#define ENABLE_TIZEN_MAIN_THREAD_SCHEDULE_DISCARD_DUPLICATE_REQUEST 1 /* Jihye Kang(jye.kang@samsung.com) : Fix lockup while doing stress test for filewriter */
+
 #endif /* OS(TIZEN) */
 
 /* ==== OS() - underlying operating system; only to be used for mandated low-level services like 
index 7ae0bc4..600686c 100644 (file)
@@ -34,6 +34,7 @@
 #include "config.h"
 #include "MainThread.h"
 
+#include "Threading.h"
 #include <Ecore.h>
 #include <wtf/OwnPtr.h>
 #include <wtf/PassOwnPtr.h>
@@ -47,8 +48,28 @@ static OwnPtr<Ecore_Pipe>& pipeObject()
     return pipeObject;
 }
 
+#if ENABLE(TIZEN_MAIN_THREAD_SCHEDULE_DISCARD_DUPLICATE_REQUEST)
+static Mutex& scheduleRequestedMutex()
+{
+    DEFINE_STATIC_LOCAL(Mutex, staticMutex, ());
+    return staticMutex;
+}
+
+static bool& scheduleRequested()
+{
+    DEFINE_STATIC_LOCAL(bool, staticScheduleRequested, ());
+    return staticScheduleRequested;
+}
+#endif
+
 static void monitorDispatchFunctions(void*, void*, unsigned int)
 {
+#if ENABLE(TIZEN_MAIN_THREAD_SCHEDULE_DISCARD_DUPLICATE_REQUEST)
+    {
+        MutexLocker locker(scheduleRequestedMutex());
+        scheduleRequested() = false;
+    }
+#endif
     dispatchFunctionsFromMainThread();
 }
 
@@ -65,7 +86,25 @@ void initializeMainThreadPlatform()
 
 void scheduleDispatchFunctionsOnMainThread()
 {
+#if ENABLE(TIZEN_MAIN_THREAD_SCHEDULE_DISCARD_DUPLICATE_REQUEST)
+    {
+        MutexLocker locker(scheduleRequestedMutex());
+        if (scheduleRequested())
+            return;
+        scheduleRequested() = true;
+    }
+
+    Eina_Bool result = false;
+    while (!result) {
+        result = ecore_pipe_write(pipeObject().get(), "", 0);
+        if (!result) {
+            TIZEN_LOGE("Failed to write shceduleDispatchFunction pipe message");
+            pipeObject() = adoptPtr(ecore_pipe_add(monitorDispatchFunctions, 0));
+        }
+    }
+#else
     ecore_pipe_write(pipeObject().get(), "", 0);
+#endif
 }
 
 }