Index: third_party/mojo/src/mojo/public/go/bindings/util.go |
diff --git a/third_party/mojo/src/mojo/public/go/bindings/util.go b/third_party/mojo/src/mojo/public/go/bindings/util.go |
index 8d51ddb721cabec0606d38096ba7b2893ef3c28c..7886fe3d6b281cc66d34071698473e498313be24 100644 |
--- a/third_party/mojo/src/mojo/public/go/bindings/util.go |
+++ b/third_party/mojo/src/mojo/public/go/bindings/util.go |
@@ -4,6 +4,13 @@ |
package bindings |
+import ( |
+ "fmt" |
+ "sync/atomic" |
+ |
+ "mojo/public/go/system" |
+) |
+ |
func align(size, alignment int) int { |
return ((size - 1) | (alignment - 1)) + 1 |
} |
@@ -14,7 +21,27 @@ func bytesForBits(bits uint64) int { |
return int((bits + 7) / 8) |
} |
+// WriteMessage writes a message to a message pipe. |
+func WriteMessage(handle system.MessagePipeHandle, message *Message) error { |
+ result := handle.WriteMessage(message.Bytes, message.Handles, system.MOJO_WRITE_MESSAGE_FLAG_NONE) |
+ if result != system.MOJO_RESULT_OK { |
+ return fmt.Errorf("error writing message: %v", result) |
+ } |
+ return nil |
+} |
+ |
// StringPointer converts provided string to *string. |
func StringPointer(s string) *string { |
return &s |
} |
+ |
+// Counter is a simple thread-safe lock-free counter that can issue unique |
+// numbers starting from 1 to callers. |
+type Counter struct { |
+ last uint64 |
+} |
+ |
+// Next returns next unused value, each value is returned only once. |
+func (c *Counter) Next() uint64 { |
+ return atomic.AddUint64(&c.last, 1) |
+} |