Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1457)

Unified Diff: third_party/mojo/src/mojo/public/go/system/shared_buffer.go

Issue 1019173002: Update mojo sdk to rev 7214b7ec7d27563b2666afad86cf1c5895c56c18 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Keep permission service alive if embedder drops requests Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: third_party/mojo/src/mojo/public/go/system/shared_buffer.go
diff --git a/third_party/mojo/src/mojo/public/go/system/shared_buffer.go b/third_party/mojo/src/mojo/public/go/system/shared_buffer.go
index 927c7ea3d6433a2ba3a79e2520437822d196fe63..925ee353d637658d9ea48594509e2780ed7a6451 100644
--- a/third_party/mojo/src/mojo/public/go/system/shared_buffer.go
+++ b/third_party/mojo/src/mojo/public/go/system/shared_buffer.go
@@ -4,10 +4,10 @@
package system
-//#include "c_allocators.h"
-//#include "mojo/public/c/system/core.h"
-import "C"
-import "unsafe"
+import (
+ "reflect"
+ "unsafe"
+)
// SharedBufferHandle is a handle for a buffer that can be shared between
// applications.
@@ -27,35 +27,49 @@ type SharedBufferHandle interface {
}
type sharedBuffer struct {
+ // baseHandle should always be the first component of this struct,
+ // see |finalizeHandle()| for more details.
baseHandle
}
func (h *sharedBuffer) DuplicateBufferHandle(opts *DuplicateBufferHandleOptions) (MojoResult, SharedBufferHandle) {
+ var flags uint32
+ if opts != nil {
+ flags = uint32(opts.flags)
+ }
h.core.mu.Lock()
- defer h.core.mu.Unlock()
-
- cParams := C.MallocDuplicateBufferHandleParams()
- defer C.FreeDuplicateBufferHandleParams(cParams)
- result := C.MojoDuplicateBufferHandle(h.mojoHandle.cValue(), opts.cValue(cParams.opts), cParams.duplicate)
- return MojoResult(result), core.acquireCHandle(*cParams.duplicate).ToSharedBufferHandle()
+ r, dup := sysImpl.DuplicateBufferHandle(uint32(h.mojoHandle), flags)
+ h.core.mu.Unlock()
+ return MojoResult(r), core.AcquireNativeHandle(MojoHandle(dup)).ToSharedBufferHandle()
}
func (h *sharedBuffer) MapBuffer(offset uint64, numBytes int, flags MojoMapBufferFlags) (MojoResult, []byte) {
h.core.mu.Lock()
- defer h.core.mu.Unlock()
-
- cParams := C.MallocMapBufferParams()
- defer C.FreeMapBufferParams(cParams)
- result := C.MojoMapBuffer(h.mojoHandle.cValue(), C.uint64_t(offset), C.uint64_t(numBytes), cParams.buffer, flags.cValue())
- if result != C.MOJO_RESULT_OK {
- return MojoResult(result), nil
+ r, buf := sysImpl.MapBuffer(uint32(h.mojoHandle), offset, uint64(numBytes), uint32(flags))
+ h.core.mu.Unlock()
+ if r != 0 {
+ return MojoResult(r), nil
}
- return MOJO_RESULT_OK, unsafeByteSlice(unsafe.Pointer(*cParams.buffer), numBytes)
+
+ return MojoResult(r), buf
}
func (h *sharedBuffer) UnmapBuffer(buffer []byte) MojoResult {
h.core.mu.Lock()
- defer h.core.mu.Unlock()
+ r := sysImpl.UnmapBuffer(buffer)
+ h.core.mu.Unlock()
+ return MojoResult(r)
+}
+
+func newUnsafeSlice(ptr unsafe.Pointer, length int) unsafe.Pointer {
+ header := &reflect.SliceHeader{
+ Data: uintptr(ptr),
+ Len: length,
+ Cap: length,
+ }
+ return unsafe.Pointer(header)
+}
- return MojoResult(C.MojoUnmapBuffer(unsafe.Pointer(&buffer[0])))
+func unsafeByteSlice(ptr unsafe.Pointer, length int) []byte {
+ return *(*[]byte)(newUnsafeSlice(ptr, length))
}
« no previous file with comments | « third_party/mojo/src/mojo/public/go/system/mojo_types.go ('k') | third_party/mojo/src/mojo/public/go/system/system.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698