Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1767)

Unified Diff: mojo/public/python/mojo/system.pyx

Issue 644773002: mojo: Add RunLoop::Current() and refactor unit tests. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « mojo/public/python/mojo/c_environment.pxd ('k') | mojo/python/tests/async_wait_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/public/python/mojo/system.pyx
diff --git a/mojo/public/python/mojo/system.pyx b/mojo/public/python/mojo/system.pyx
index 4768247e695fcca555f565627786f725f9d59908..b2d074b0ce0237967e77b79374ef91c9262d595d 100644
--- a/mojo/public/python/mojo/system.pyx
+++ b/mojo/public/python/mojo/system.pyx
@@ -17,6 +17,9 @@ from cpython.buffer cimport PyObject_GetBuffer
from cpython.mem cimport PyMem_Malloc, PyMem_Free
from libc.stdint cimport int32_t, int64_t, uint32_t, uint64_t, uintptr_t
+import ctypes
+import threading
+
def SetSystemThunks(system_thunks_as_object):
"""Bind the basic Mojo Core functions.
@@ -711,10 +714,28 @@ class DuplicateSharedBufferOptions(object):
self.flags = DuplicateSharedBufferOptions.FLAG_NONE
+_RUN_LOOPS = threading.local()
sdefresne 2014/10/10 12:29:44 IIUC, _RUN_LOOPS is used to keep a weak-ref to the
qsr 2014/10/10 12:34:07 Done.
+
+
cdef class RunLoop(object):
"""RunLoop to use when using asynchronous operations on handles."""
- cdef c_environment.CRunLoop c_run_loop
+ cdef c_environment.CRunLoop* c_run_loop
+
+ def __init__(self):
+ assert not <uintptr_t>(c_environment.CRunLoopCurrent())
+ self.c_run_loop = new c_environment.CRunLoop()
+ _RUN_LOOPS.loop = id(self)
+
+ def __dealloc__(self):
+ del _RUN_LOOPS.loop
+ del self.c_run_loop
+
+ @staticmethod
+ def Current():
+ if hasattr(_RUN_LOOPS, 'loop'):
+ return ctypes.cast(_RUN_LOOPS.loop, ctypes.py_object).value
+ return None
def Run(self):
"""Run the runloop until Quit is called."""
« no previous file with comments | « mojo/public/python/mojo/c_environment.pxd ('k') | mojo/python/tests/async_wait_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698