| 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 package impl | 5 package impl |
| 6 | 6 |
| 7 //#include "mojo/public/platform/native/system_thunks.h" | 7 //#include "mojo/public/platform/native/system_thunks.h" |
| 8 //#include "mojo/public/c/system/main.h" | 8 //#include "mojo/public/c/system/main.h" |
| 9 import "C" | 9 import "C" |
| 10 import "unsafe" | 10 import "unsafe" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 } | 24 } |
| 25 | 25 |
| 26 func (c *CoreImpl) GetTimeTicksNow() MojoTimeTicks { | 26 func (c *CoreImpl) GetTimeTicksNow() MojoTimeTicks { |
| 27 return (MojoTimeTicks)(C.MojoGetTimeTicksNow()) | 27 return (MojoTimeTicks)(C.MojoGetTimeTicksNow()) |
| 28 } | 28 } |
| 29 | 29 |
| 30 func (c *CoreImpl) Close(handle MojoHandle) MojoResult { | 30 func (c *CoreImpl) Close(handle MojoHandle) MojoResult { |
| 31 return (MojoResult)(C.MojoClose(handle.cType())) | 31 return (MojoResult)(C.MojoClose(handle.cType())) |
| 32 } | 32 } |
| 33 | 33 |
| 34 func (c *CoreImpl) Wait(handle MojoHandle, signal MojoHandleSignals, deadline Mo
joDeadline) MojoResult { | 34 func (c *CoreImpl) Wait(handle MojoHandle, signal MojoHandleSignals, deadline Mo
joDeadline) (MojoResult, *MojoHandleSignalsState) { |
| 35 » return (MojoResult)(C.MojoWait(handle.cType(), signal.cType(), deadline.
cType())) | 35 » var signal_states C.struct_MojoHandleSignalsState |
| 36 » result := C.MojoNewWait(handle.cType(), signal.cType(), deadline.cType()
, &signal_states) |
| 37 » return MojoResult(result), &MojoHandleSignalsState{MojoHandleSignals(sig
nal_states.satisfied_signals), MojoHandleSignals(signal_states.satisfiable_signa
ls)} |
| 36 } | 38 } |
| 37 | 39 |
| 38 func (c *CoreImpl) WaitMany(handles []MojoHandle, signals []MojoHandleSignals, d
eadline MojoDeadline) MojoResult { | 40 func (c *CoreImpl) WaitMany(handles []MojoHandle, signals []MojoHandleSignals, d
eadline MojoDeadline) (result MojoResult, index *uint32, state []MojoHandleSigna
lsState) { |
| 39 » return (MojoResult)(C.MojoWaitMany(cArrayMojoHandle(handles), cArrayMojo
HandleSignals(signals), (C.uint32_t)(len(handles)), deadline.cType())) | 41 » // Set "-1" using the instructions from http://blog.golang.org/constants |
| 42 » cindex := ^C.uint32_t(0) |
| 43 » cstate := make([]C.struct_MojoHandleSignalsState, len(handles)) |
| 44 |
| 45 » result = (MojoResult)(C.MojoNewWaitMany(cArrayMojoHandle(handles), cArra
yMojoHandleSignals(signals), (C.uint32_t)(len(handles)), deadline.cType(), &cind
ex, &cstate[0])) |
| 46 |
| 47 » if uint32(cindex) < uint32(len(handles)) { |
| 48 » » temp := uint32(cindex) |
| 49 » » index = &temp |
| 50 » } |
| 51 |
| 52 » if result != MOJO_RESULT_INVALID_ARGUMENT && result != MOJO_RESULT_RESOU
RCE_EXHAUSTED { |
| 53 » » state = make([]MojoHandleSignalsState, len(cstate)) |
| 54 » » for i, value := range cstate { |
| 55 » » » state[i] = NewMojoHandleSignalsState(value) |
| 56 » » } |
| 57 » } |
| 58 |
| 59 » return |
| 40 } | 60 } |
| 41 | 61 |
| 42 func (c *CoreImpl) CreateMessagePipe(opts *MessagePipeOptions) (MojoResult, Mojo
Handle, MojoHandle) { | 62 func (c *CoreImpl) CreateMessagePipe(opts *MessagePipeOptions) (MojoResult, Mojo
Handle, MojoHandle) { |
| 43 var handle0, handle1 C.MojoHandle | 63 var handle0, handle1 C.MojoHandle |
| 44 result := C.MojoCreateMessagePipe(opts.cType(), &handle0, &handle1) | 64 result := C.MojoCreateMessagePipe(opts.cType(), &handle0, &handle1) |
| 45 return (MojoResult)(result), (MojoHandle)(handle0), (MojoHandle)(handle1
) | 65 return (MojoResult)(result), (MojoHandle)(handle0), (MojoHandle)(handle1
) |
| 46 } | 66 } |
| 47 | 67 |
| 48 func (c *CoreImpl) WriteMessage(handle MojoHandle, msg []byte, attached []MojoHa
ndle, flags MojoWriteMessageFlags) MojoResult { | 68 func (c *CoreImpl) WriteMessage(handle MojoHandle, msg []byte, attached []MojoHa
ndle, flags MojoWriteMessageFlags) MojoResult { |
| 49 return (MojoResult)(C.MojoWriteMessage(handle.cType(), cArrayBytes(msg),
(C.uint32_t)(len(msg)), cArrayMojoHandle(attached), (C.uint32_t)(len(attached))
, flags.cType())) | 69 return (MojoResult)(C.MojoWriteMessage(handle.cType(), cArrayBytes(msg),
(C.uint32_t)(len(msg)), cArrayMojoHandle(attached), (C.uint32_t)(len(attached))
, flags.cType())) |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 100 result := C.MojoMapBuffer(handle.cType(), (C.uint64_t)(offset), (C.uint6
4_t)(numBytes), &bufPtr, flags.cType()) | 120 result := C.MojoMapBuffer(handle.cType(), (C.uint64_t)(offset), (C.uint6
4_t)(numBytes), &bufPtr, flags.cType()) |
| 101 if result != C.MOJO_RESULT_OK { | 121 if result != C.MOJO_RESULT_OK { |
| 102 return (MojoResult)(result), nil | 122 return (MojoResult)(result), nil |
| 103 } | 123 } |
| 104 return MOJO_RESULT_OK, bufPtr | 124 return MOJO_RESULT_OK, bufPtr |
| 105 } | 125 } |
| 106 | 126 |
| 107 func (c *CoreImpl) UnmapBuffer(buffer unsafe.Pointer) MojoResult { | 127 func (c *CoreImpl) UnmapBuffer(buffer unsafe.Pointer) MojoResult { |
| 108 return (MojoResult)(C.MojoUnmapBuffer(buffer)) | 128 return (MojoResult)(C.MojoUnmapBuffer(buffer)) |
| 109 } | 129 } |
| OLD | NEW |