Index: mojo/android/system/src/org/chromium/mojo/system/impl/CoreImpl.java |
diff --git a/mojo/android/system/src/org/chromium/mojo/system/impl/CoreImpl.java b/mojo/android/system/src/org/chromium/mojo/system/impl/CoreImpl.java |
index 19b2d29fabb61c061968ab41baa1349eead62091..a32e1f347b88ff0f8cfffda40a7ba5d9c890d13c 100644 |
--- a/mojo/android/system/src/org/chromium/mojo/system/impl/CoreImpl.java |
+++ b/mojo/android/system/src/org/chromium/mojo/system/impl/CoreImpl.java |
@@ -16,6 +16,7 @@ import org.chromium.mojo.system.MessagePipeHandle; |
import org.chromium.mojo.system.MojoException; |
import org.chromium.mojo.system.MojoResult; |
import org.chromium.mojo.system.Pair; |
+import org.chromium.mojo.system.RunLoop; |
import org.chromium.mojo.system.SharedBufferHandle; |
import org.chromium.mojo.system.SharedBufferHandle.DuplicateOptions; |
import org.chromium.mojo.system.SharedBufferHandle.MapFlags; |
@@ -55,6 +56,11 @@ public class CoreImpl implements Core, AsyncWaiter { |
private static class LazyHolder { private static final Core INSTANCE = new CoreImpl(); } |
/** |
+ * The run loop for the current thread. |
+ */ |
+ private ThreadLocal<BaseRunLoop> mCurrentRunLoop = new ThreadLocal<BaseRunLoop>(); |
+ |
+ /** |
* @return the instance. |
*/ |
public static Core getInstance() { |
@@ -206,6 +212,34 @@ public class CoreImpl implements Core, AsyncWaiter { |
} |
/** |
+ * @see Core#createDefaultRunLoop() |
+ */ |
+ @Override |
+ public RunLoop createDefaultRunLoop() { |
+ if (mCurrentRunLoop.get() != null) { |
+ throw new MojoException(MojoResult.FAILED_PRECONDITION); |
+ } |
+ BaseRunLoop runLoop = new BaseRunLoop(this); |
+ mCurrentRunLoop.set(runLoop); |
+ return runLoop; |
+ } |
+ |
+ /** |
+ * @see Core#getCurrentRunLoop() |
+ */ |
+ @Override |
+ public RunLoop getCurrentRunLoop() { |
+ return mCurrentRunLoop.get(); |
+ } |
+ |
+ /** |
+ * Remove the current run loop. |
+ */ |
+ void clearCurrentRunLoop() { |
+ mCurrentRunLoop.remove(); |
+ } |
+ |
+ /** |
* @see AsyncWaiter#asyncWait(Handle, Core.HandleSignals, long, Callback) |
*/ |
@Override |