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

Side by Side Diff: mojo/public/go/bindings/util.go

Issue 2250183003: Make the fuchsia mojo/public repo the source of truth. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 4 years, 4 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 unified diff | Download patch
« no previous file with comments | « mojo/public/go/bindings/stub.go ('k') | mojo/public/go/system/core.go » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 package bindings
6
7 import (
8 "sync/atomic"
9
10 "mojo/public/go/system"
11 )
12
13 func align(size, alignment int) int {
14 return ((size - 1) | (alignment - 1)) + 1
15 }
16
17 // bytesForBits returns minimum number of bytes required to store provided
18 // number of bits.
19 func bytesForBits(bits uint64) int {
20 return int((bits + 7) / 8)
21 }
22
23 // WriteMessage writes a message to a message pipe.
24 func WriteMessage(handle system.MessagePipeHandle, message *Message) error {
25 result := handle.WriteMessage(message.Bytes, message.Handles, system.MOJ O_WRITE_MESSAGE_FLAG_NONE)
26 if result != system.MOJO_RESULT_OK {
27 return &ConnectionError{result}
28 }
29 return nil
30 }
31
32 // StringPointer converts provided string to *string.
33 func StringPointer(s string) *string {
34 return &s
35 }
36
37 // Counter is a simple thread-safe lock-free counter that can issue unique
38 // numbers starting from 1 to callers.
39 type Counter interface {
40 // Count returns next unused value, each value is returned only once.
41 Count() uint64
42 }
43
44 // NewCounter return a new counter that returns numbers starting from 1.
45 func NewCounter() Counter {
46 return &counterImpl{}
47 }
48
49 // counterImpl implements Counter interface.
50 // This implementation uses atomic operations on an uint64, it should be always
51 // allocated separatelly to be 8-aligned in order to work correctly on ARM.
52 // See http://golang.org/pkg/sync/atomic/#pkg-note-BUG.
53 type counterImpl struct {
54 last uint64
55 }
56
57 func (c *counterImpl) Count() uint64 {
58 return atomic.AddUint64(&c.last, 1)
59 }
OLDNEW
« no previous file with comments | « mojo/public/go/bindings/stub.go ('k') | mojo/public/go/system/core.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698