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.""" |