| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 system | 5 package system |
| 6 | 6 |
| 7 //#include "c_allocators.h" | 7 //#include "c_allocators.h" |
| 8 //#include "mojo/public/c/system/core.h" | 8 //#include "mojo/public/c/system/core.h" |
| 9 import "C" | 9 import "C" |
| 10 import "unsafe" | 10 import "unsafe" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 | 24 |
| 25 // UnmapBuffer unmaps a buffer that was returned by MapBuffer. | 25 // UnmapBuffer unmaps a buffer that was returned by MapBuffer. |
| 26 UnmapBuffer(buffer []byte) MojoResult | 26 UnmapBuffer(buffer []byte) MojoResult |
| 27 } | 27 } |
| 28 | 28 |
| 29 type sharedBuffer struct { | 29 type sharedBuffer struct { |
| 30 baseHandle | 30 baseHandle |
| 31 } | 31 } |
| 32 | 32 |
| 33 func (h *sharedBuffer) DuplicateBufferHandle(opts *DuplicateBufferHandleOptions)
(MojoResult, SharedBufferHandle) { | 33 func (h *sharedBuffer) DuplicateBufferHandle(opts *DuplicateBufferHandleOptions)
(MojoResult, SharedBufferHandle) { |
| 34 h.core.mu.Lock() |
| 35 defer h.core.mu.Unlock() |
| 36 |
| 34 cParams := C.MallocDuplicateBufferHandleParams() | 37 cParams := C.MallocDuplicateBufferHandleParams() |
| 35 defer C.FreeDuplicateBufferHandleParams(cParams) | 38 defer C.FreeDuplicateBufferHandleParams(cParams) |
| 36 result := C.MojoDuplicateBufferHandle(h.mojoHandle.cValue(), opts.cValue
(cParams.opts), cParams.duplicate) | 39 result := C.MojoDuplicateBufferHandle(h.mojoHandle.cValue(), opts.cValue
(cParams.opts), cParams.duplicate) |
| 37 return MojoResult(result), core.acquireCHandle(*cParams.duplicate).ToSha
redBufferHandle() | 40 return MojoResult(result), core.acquireCHandle(*cParams.duplicate).ToSha
redBufferHandle() |
| 38 } | 41 } |
| 39 | 42 |
| 40 func (h *sharedBuffer) MapBuffer(offset uint64, numBytes int, flags MojoMapBuffe
rFlags) (MojoResult, []byte) { | 43 func (h *sharedBuffer) MapBuffer(offset uint64, numBytes int, flags MojoMapBuffe
rFlags) (MojoResult, []byte) { |
| 44 h.core.mu.Lock() |
| 45 defer h.core.mu.Unlock() |
| 46 |
| 41 cParams := C.MallocMapBufferParams() | 47 cParams := C.MallocMapBufferParams() |
| 42 defer C.FreeMapBufferParams(cParams) | 48 defer C.FreeMapBufferParams(cParams) |
| 43 result := C.MojoMapBuffer(h.mojoHandle.cValue(), C.uint64_t(offset), C.u
int64_t(numBytes), cParams.buffer, flags.cValue()) | 49 result := C.MojoMapBuffer(h.mojoHandle.cValue(), C.uint64_t(offset), C.u
int64_t(numBytes), cParams.buffer, flags.cValue()) |
| 44 if result != C.MOJO_RESULT_OK { | 50 if result != C.MOJO_RESULT_OK { |
| 45 return MojoResult(result), nil | 51 return MojoResult(result), nil |
| 46 } | 52 } |
| 47 return MOJO_RESULT_OK, unsafeByteSlice(unsafe.Pointer(*cParams.buffer),
numBytes) | 53 return MOJO_RESULT_OK, unsafeByteSlice(unsafe.Pointer(*cParams.buffer),
numBytes) |
| 48 } | 54 } |
| 49 | 55 |
| 50 func (h *sharedBuffer) UnmapBuffer(buffer []byte) MojoResult { | 56 func (h *sharedBuffer) UnmapBuffer(buffer []byte) MojoResult { |
| 57 h.core.mu.Lock() |
| 58 defer h.core.mu.Unlock() |
| 59 |
| 51 return MojoResult(C.MojoUnmapBuffer(unsafe.Pointer(&buffer[0]))) | 60 return MojoResult(C.MojoUnmapBuffer(unsafe.Pointer(&buffer[0]))) |
| 52 } | 61 } |
| OLD | NEW |