| OLD | NEW |
| 1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 # distutils language = c++ | 5 # distutils language = c++ |
| 6 | 6 |
| 7 cimport c_core | 7 cimport c_core |
| 8 cimport c_export # needed so the init function gets exported | 8 cimport c_export # needed so the init function gets exported |
| 9 cimport c_thunks | 9 cimport c_thunks |
| 10 | 10 |
| 11 | 11 |
| 12 from cpython.buffer cimport PyBUF_CONTIG | 12 from cpython.buffer cimport PyBUF_CONTIG |
| 13 from cpython.buffer cimport PyBUF_CONTIG_RO | 13 from cpython.buffer cimport PyBUF_CONTIG_RO |
| 14 from cpython.buffer cimport Py_buffer | 14 from cpython.buffer cimport Py_buffer |
| 15 from cpython.buffer cimport PyBuffer_FillInfo | 15 from cpython.buffer cimport PyBuffer_FillInfo |
| 16 from cpython.buffer cimport PyBuffer_Release | 16 from cpython.buffer cimport PyBuffer_Release |
| 17 from cpython.buffer cimport PyObject_GetBuffer | 17 from cpython.buffer cimport PyObject_GetBuffer |
| 18 from cpython.mem cimport PyMem_Malloc, PyMem_Free | 18 from cpython.mem cimport PyMem_Malloc, PyMem_Free |
| 19 from cpython.object cimport Py_EQ, Py_NE | 19 from cpython.object cimport Py_EQ, Py_NE |
| 20 from libc.stdint cimport int32_t, int64_t, uint32_t, uint64_t, uintptr_t | 20 from libc.stdint cimport int32_t, int64_t, uint32_t, uint64_t, uintptr_t |
| 21 | 21 |
| 22 import ctypes | 22 import ctypes |
| 23 import threading | 23 import threading |
| 24 | 24 |
| 25 import mojo.system_impl | 25 import mojo_system_impl |
| 26 | 26 |
| 27 def SetSystemThunks(system_thunks_as_object): | 27 def SetSystemThunks(system_thunks_as_object): |
| 28 """Bind the basic Mojo Core functions. | 28 """Bind the basic Mojo Core functions. |
| 29 | 29 |
| 30 This should only be used by the embedder. | 30 This should only be used by the embedder. |
| 31 """ | 31 """ |
| 32 cdef const c_thunks.MojoSystemThunks* system_thunks = ( | 32 cdef const c_thunks.MojoSystemThunks* system_thunks = ( |
| 33 <const c_thunks.MojoSystemThunks*><uintptr_t>system_thunks_as_object) | 33 <const c_thunks.MojoSystemThunks*><uintptr_t>system_thunks_as_object) |
| 34 c_thunks.MojoSetSystemThunks(system_thunks) | 34 c_thunks.MojoSetSystemThunks(system_thunks) |
| 35 | 35 |
| (...skipping 726 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 | 762 |
| 763 | 763 |
| 764 # Keeps a thread local weak reference to the current run loop. | 764 # Keeps a thread local weak reference to the current run loop. |
| 765 _RUN_LOOPS = threading.local() | 765 _RUN_LOOPS = threading.local() |
| 766 | 766 |
| 767 | 767 |
| 768 class RunLoop(object): | 768 class RunLoop(object): |
| 769 """RunLoop to use when using asynchronous operations on handles.""" | 769 """RunLoop to use when using asynchronous operations on handles.""" |
| 770 | 770 |
| 771 def __init__(self): | 771 def __init__(self): |
| 772 self.__run_loop = mojo.system_impl.RunLoop() | 772 self.__run_loop = mojo_system_impl.RunLoop() |
| 773 _RUN_LOOPS.loop = id(self) | 773 _RUN_LOOPS.loop = id(self) |
| 774 | 774 |
| 775 def __del__(self): | 775 def __del__(self): |
| 776 del _RUN_LOOPS.loop | 776 del _RUN_LOOPS.loop |
| 777 | 777 |
| 778 def Run(self): | 778 def Run(self): |
| 779 """Run the runloop until Quit is called.""" | 779 """Run the runloop until Quit is called.""" |
| 780 return self.__run_loop.Run() | 780 return self.__run_loop.Run() |
| 781 | 781 |
| 782 def RunUntilIdle(self): | 782 def RunUntilIdle(self): |
| (...skipping 11 matching lines...) Expand all Loading... |
| 794 """ | 794 """ |
| 795 return self.__run_loop.PostDelayedTask(runnable, delay) | 795 return self.__run_loop.PostDelayedTask(runnable, delay) |
| 796 | 796 |
| 797 @staticmethod | 797 @staticmethod |
| 798 def Current(): | 798 def Current(): |
| 799 if hasattr(_RUN_LOOPS, 'loop'): | 799 if hasattr(_RUN_LOOPS, 'loop'): |
| 800 return ctypes.cast(_RUN_LOOPS.loop, ctypes.py_object).value | 800 return ctypes.cast(_RUN_LOOPS.loop, ctypes.py_object).value |
| 801 return None | 801 return None |
| 802 | 802 |
| 803 | 803 |
| 804 _ASYNC_WAITER = mojo.system_impl.AsyncWaiter() | 804 _ASYNC_WAITER = mojo_system_impl.AsyncWaiter() |
| OLD | NEW |