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

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

Issue 910883002: Update mojo sdk to rev 8af2ccff2eee4bfca1043015abee30482a030b30 (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Apply 9f87aeadbda22441b7d469e596f7bd7d0d73e2a8 (https://codereview.chromium.org/908973002/) Created 5 years, 10 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/core.go
diff --git a/third_party/mojo/src/mojo/public/go/system/core.go b/third_party/mojo/src/mojo/public/go/system/core.go
index e1b8cd4d50a37ef40f7859e9f435e6122537902a..da6313e0be764076e2b69fa6fdaa5b181b290dfb 100644
--- a/third_party/mojo/src/mojo/public/go/system/core.go
+++ b/third_party/mojo/src/mojo/public/go/system/core.go
@@ -9,6 +9,7 @@ package system
import "C"
import (
"reflect"
+ "sync"
"unsafe"
)
@@ -57,8 +58,21 @@ type Core interface {
// coreImpl is an implementation of the Mojo system APIs.
type coreImpl struct {
+ // Protects from making parallel non-blocking mojo cgo calls.
+ mu sync.Mutex
}
+// GetCore returns singleton instance of the Mojo system APIs implementation.
+//
+// The implementation uses cgo to call native mojo APIs implementation. Each cgo
+// call uses a separate thread for execution. To limit the number of used
+// threads all non-blocking system calls (i.e. all system calls except |Wait|
+// and |WaitMany|) on this implementation and on handles returned by this
+// implementation are protected by a mutex so that if you make two parallel
+// system calls one will wait for another to finish before executing.
+// However, |Wait| and |WaitMany| are not protected by a mutex and each parallel
+// call will use a separate thread. To reduce number of threads used for |Wait|
+// calls prefer to use |WaitMany|.
func GetCore() Core {
return &core
}
@@ -68,10 +82,13 @@ func (impl *coreImpl) acquireCHandle(handle C.MojoHandle) UntypedHandle {
}
func (impl *coreImpl) AcquireNativeHandle(handle MojoHandle) UntypedHandle {
- return &untypedHandleImpl{baseHandle{handle}}
+ return &untypedHandleImpl{baseHandle{impl, handle}}
}
func (impl *coreImpl) GetTimeTicksNow() MojoTimeTicks {
+ impl.mu.Lock()
+ defer impl.mu.Unlock()
+
return MojoTimeTicks(C.MojoGetTimeTicksNow())
}
@@ -108,6 +125,9 @@ func (impl *coreImpl) WaitMany(handles []Handle, signals []MojoHandleSignals, de
}
func (impl *coreImpl) CreateDataPipe(opts *DataPipeOptions) (MojoResult, ProducerHandle, ConsumerHandle) {
+ impl.mu.Lock()
+ defer impl.mu.Unlock()
+
cParams := C.MallocCreateDataPipeParams()
defer C.FreeCreateDataPipeParams(cParams)
result := C.MojoCreateDataPipe(opts.cValue(cParams.opts), cParams.producer, cParams.consumer)
@@ -117,6 +137,9 @@ func (impl *coreImpl) CreateDataPipe(opts *DataPipeOptions) (MojoResult, Produce
}
func (impl *coreImpl) CreateMessagePipe(opts *MessagePipeOptions) (MojoResult, MessagePipeHandle, MessagePipeHandle) {
+ impl.mu.Lock()
+ defer impl.mu.Unlock()
+
cParams := C.MallocCreateMessagePipeParams()
defer C.FreeCreateMessagePipeParams(cParams)
result := C.MojoCreateMessagePipe(opts.cValue(cParams.opts), cParams.handle0, cParams.handle1)
@@ -126,6 +149,9 @@ func (impl *coreImpl) CreateMessagePipe(opts *MessagePipeOptions) (MojoResult, M
}
func (impl *coreImpl) CreateSharedBuffer(opts *SharedBufferOptions, numBytes uint64) (MojoResult, SharedBufferHandle) {
+ impl.mu.Lock()
+ defer impl.mu.Unlock()
+
cParams := C.MallocCreateSharedBufferParams()
defer C.FreeCreateSharedBufferParams(cParams)
result := C.MojoCreateSharedBuffer(opts.cValue(cParams.opts), C.uint64_t(numBytes), cParams.handle)

Powered by Google App Engine
This is Rietveld 408576698