| 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 |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 READ_DATA_FLAG_QUERY = c_core.MOJO_READ_DATA_FLAG_QUERY | 68 READ_DATA_FLAG_QUERY = c_core.MOJO_READ_DATA_FLAG_QUERY |
| 69 READ_DATA_FLAG_PEEK = c_core.MOJO_READ_DATA_FLAG_PEEK | 69 READ_DATA_FLAG_PEEK = c_core.MOJO_READ_DATA_FLAG_PEEK |
| 70 MAP_BUFFER_FLAG_NONE = c_core.MOJO_MAP_BUFFER_FLAG_NONE | 70 MAP_BUFFER_FLAG_NONE = c_core.MOJO_MAP_BUFFER_FLAG_NONE |
| 71 | 71 |
| 72 _WAITMANY_NO_SIGNAL_STATE_ERRORS = [RESULT_INVALID_ARGUMENT, | 72 _WAITMANY_NO_SIGNAL_STATE_ERRORS = [RESULT_INVALID_ARGUMENT, |
| 73 RESULT_RESOURCE_EXHAUSTED] | 73 RESULT_RESOURCE_EXHAUSTED] |
| 74 | 74 |
| 75 def GetTimeTicksNow(): | 75 def GetTimeTicksNow(): |
| 76 """Monotonically increasing tick count representing "right now." | 76 """Monotonically increasing tick count representing "right now." |
| 77 | 77 |
| 78 See mojo/public/c/system/functions.h | 78 See mojo/public/c/system/time.h |
| 79 """ | 79 """ |
| 80 return c_core.MojoGetTimeTicksNow() | 80 return c_core.MojoGetTimeTicksNow() |
| 81 | 81 |
| 82 cdef class _ScopedMemory: | 82 cdef class _ScopedMemory: |
| 83 """Allocate memory at creation, and deallocate it at destruction.""" | 83 """Allocate memory at creation, and deallocate it at destruction.""" |
| 84 cdef void* memory | 84 cdef void* memory |
| 85 def __init__(self, size): | 85 def __init__(self, size): |
| 86 self.memory = PyMem_Malloc(size) | 86 self.memory = PyMem_Malloc(size) |
| 87 | 87 |
| 88 def __dealloc__(self): | 88 def __dealloc__(self): |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 196 | 196 |
| 197 def __init__(self, mojo_result): | 197 def __init__(self, mojo_result): |
| 198 self.mojo_result = mojo_result | 198 self.mojo_result = mojo_result |
| 199 | 199 |
| 200 def WaitMany(handles_and_signals, deadline): | 200 def WaitMany(handles_and_signals, deadline): |
| 201 """Waits on a list of handles. | 201 """Waits on a list of handles. |
| 202 | 202 |
| 203 Args: | 203 Args: |
| 204 handles_and_signals: list of tuples of handle and signal. | 204 handles_and_signals: list of tuples of handle and signal. |
| 205 | 205 |
| 206 See mojo/public/c/system/functions.h | 206 See mojo/public/c/system/wait.h |
| 207 """ | 207 """ |
| 208 cdef uint32_t length = len(handles_and_signals) | 208 cdef uint32_t length = len(handles_and_signals) |
| 209 cdef uint32_t result_index = <uint32_t>(-1) | 209 cdef uint32_t result_index = <uint32_t>(-1) |
| 210 | 210 |
| 211 cdef _ScopedMemory handles_alloc = _ScopedMemory( | 211 cdef _ScopedMemory handles_alloc = _ScopedMemory( |
| 212 sizeof(c_core.MojoHandle) * length) | 212 sizeof(c_core.MojoHandle) * length) |
| 213 cdef _ScopedMemory signals_alloc = _ScopedMemory( | 213 cdef _ScopedMemory signals_alloc = _ScopedMemory( |
| 214 sizeof(c_core.MojoHandleSignals) * length) | 214 sizeof(c_core.MojoHandleSignals) * length) |
| 215 cdef _ScopedMemory states_alloc = _ScopedMemory( | 215 cdef _ScopedMemory states_alloc = _ScopedMemory( |
| 216 sizeof(c_core.MojoHandleSignalsState) * length) | 216 sizeof(c_core.MojoHandleSignalsState) * length) |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 336 else: | 336 else: |
| 337 return not equality | 337 return not equality |
| 338 | 338 |
| 339 def IsValid(self): | 339 def IsValid(self): |
| 340 """Returns whether this handle is valid.""" | 340 """Returns whether this handle is valid.""" |
| 341 return self._mojo_handle != c_core.MOJO_HANDLE_INVALID | 341 return self._mojo_handle != c_core.MOJO_HANDLE_INVALID |
| 342 | 342 |
| 343 def Close(self): | 343 def Close(self): |
| 344 """Closes this handle. | 344 """Closes this handle. |
| 345 | 345 |
| 346 See mojo/public/c/system/functions.h | 346 See mojo/public/c/system/handle.h |
| 347 """ | 347 """ |
| 348 cdef c_core.MojoResult result = c_core.MOJO_RESULT_OK | 348 cdef c_core.MojoResult result = c_core.MOJO_RESULT_OK |
| 349 if self.IsValid(): | 349 if self.IsValid(): |
| 350 result = c_core.MojoClose(self._mojo_handle) | 350 result = c_core.MojoClose(self._mojo_handle) |
| 351 self._Invalidate() | 351 self._Invalidate() |
| 352 return result | 352 return result |
| 353 | 353 |
| 354 def __dealloc__(self): | 354 def __dealloc__(self): |
| 355 self.Close() | 355 self.Close() |
| 356 | 356 |
| 357 def Wait(self, signals, deadline): | 357 def Wait(self, signals, deadline): |
| 358 """Waits on the given handle. | 358 """Waits on the given handle. |
| 359 | 359 |
| 360 See mojo/public/c/system/functions.h | 360 See mojo/public/c/system/wait.h |
| 361 """ | 361 """ |
| 362 cdef c_core.MojoHandle handle = self._mojo_handle | 362 cdef c_core.MojoHandle handle = self._mojo_handle |
| 363 cdef c_core.MojoHandleSignals csignals = signals | 363 cdef c_core.MojoHandleSignals csignals = signals |
| 364 cdef c_core.MojoDeadline cdeadline = deadline | 364 cdef c_core.MojoDeadline cdeadline = deadline |
| 365 cdef c_core.MojoHandleSignalsState signal_states | 365 cdef c_core.MojoHandleSignalsState signal_states |
| 366 cdef c_core.MojoResult result | 366 cdef c_core.MojoResult result |
| 367 with nogil: | 367 with nogil: |
| 368 result = c_core.MojoWait(handle, csignals, cdeadline, &signal_states) | 368 result = c_core.MojoWait(handle, csignals, cdeadline, &signal_states) |
| 369 | 369 |
| 370 returned_states = None | 370 returned_states = None |
| (...skipping 416 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 787 return self.__run_loop.PostDelayedTask(runnable, delay) | 787 return self.__run_loop.PostDelayedTask(runnable, delay) |
| 788 | 788 |
| 789 @staticmethod | 789 @staticmethod |
| 790 def Current(): | 790 def Current(): |
| 791 if hasattr(_RUN_LOOPS, 'loop'): | 791 if hasattr(_RUN_LOOPS, 'loop'): |
| 792 return _RUN_LOOPS.loop() | 792 return _RUN_LOOPS.loop() |
| 793 return None | 793 return None |
| 794 | 794 |
| 795 | 795 |
| 796 _ASYNC_WAITER = mojo_system_impl.AsyncWaiter() | 796 _ASYNC_WAITER = mojo_system_impl.AsyncWaiter() |
| OLD | NEW |