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

Side by Side Diff: third_party/go/src/golang.org/x/mobile/bind/seq/ref.go

Issue 1275153002: Remove third_party/golang.org/x/mobile as it is no longer used with Go 1.5. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Remove golang.org/x/mobile Created 5 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
OLDNEW
(Empty)
1 // Copyright 2014 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package seq
6
7 //#cgo LDFLAGS: -llog
8 //#include <android/log.h>
9 //#include <string.h>
10 //import "C"
11
12 import (
13 "fmt"
14 "sync"
15 )
16
17 // refs stores Go objects that have been passed to another language.
18 var refs struct {
19 sync.Mutex
20 next int32 // next reference number to use for Go object, always negativ e
21 refs map[interface{}]int32
22 objs map[int32]interface{}
23 }
24
25 func init() {
26 refs.Lock()
27 refs.next = -24 // Go objects get negative reference numbers. Arbitrary starting point.
28 refs.refs = make(map[interface{}]int32)
29 refs.objs = make(map[int32]interface{})
30 refs.Unlock()
31 }
32
33 // A Ref represents a Java or Go object passed across the language
34 // boundary.
35 type Ref struct {
36 Num int32
37 }
38
39 // Get returns the underlying object.
40 func (r *Ref) Get() interface{} {
41 refs.Lock()
42 obj, ok := refs.objs[r.Num]
43 refs.Unlock()
44 if !ok {
45 panic(fmt.Sprintf("unknown ref %d", r.Num))
46 }
47 return obj
48 }
49
50 // Delete remove the reference to the underlying object.
51 func Delete(num int32) {
52 refs.Lock()
53 obj, ok := refs.objs[num]
54 if !ok {
55 panic(fmt.Sprintf("seq.Delete unknown refnum: %d", num))
56 }
57 delete(refs.objs, num)
58 delete(refs.refs, obj)
59 refs.Unlock()
60 }
OLDNEW
« no previous file with comments | « third_party/go/src/golang.org/x/mobile/bind/seq/buffer.go ('k') | third_party/go/src/golang.org/x/mobile/bind/seq/seq.go » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698