annotate libgo/misc/cgo/life/life.go @ 133:420680fc7707

do normal call in goto codesegment in normal function
author anatofuz
date Sat, 03 Nov 2018 19:49:09 +0900
parents 04ced10e8804
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 // skip
kono
parents:
diff changeset
2
kono
parents:
diff changeset
3 // Copyright 2010 The Go Authors. All rights reserved.
kono
parents:
diff changeset
4 // Use of this source code is governed by a BSD-style
kono
parents:
diff changeset
5 // license that can be found in the LICENSE file.
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 package life
kono
parents:
diff changeset
8
kono
parents:
diff changeset
9 // #include "life.h"
kono
parents:
diff changeset
10 import "C"
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 import "unsafe"
kono
parents:
diff changeset
13
kono
parents:
diff changeset
14 func Run(gen, x, y int, a []int32) {
kono
parents:
diff changeset
15 n := make([]int32, x*y)
kono
parents:
diff changeset
16 for i := 0; i < gen; i++ {
kono
parents:
diff changeset
17 C.Step(C.int(x), C.int(y), (*C.int)(unsafe.Pointer(&a[0])), (*C.int)(unsafe.Pointer(&n[0])))
kono
parents:
diff changeset
18 copy(a, n)
kono
parents:
diff changeset
19 }
kono
parents:
diff changeset
20 }
kono
parents:
diff changeset
21
kono
parents:
diff changeset
22 // Keep the channels visible from Go.
kono
parents:
diff changeset
23 var chans [4]chan bool
kono
parents:
diff changeset
24
kono
parents:
diff changeset
25 //export GoStart
kono
parents:
diff changeset
26 // Double return value is just for testing.
kono
parents:
diff changeset
27 func GoStart(i, xdim, ydim, xstart, xend, ystart, yend C.int, a *C.int, n *C.int) (int, int) {
kono
parents:
diff changeset
28 c := make(chan bool, int(C.MYCONST))
kono
parents:
diff changeset
29 go func() {
kono
parents:
diff changeset
30 C.DoStep(xdim, ydim, xstart, xend, ystart, yend, a, n)
kono
parents:
diff changeset
31 c <- true
kono
parents:
diff changeset
32 }()
kono
parents:
diff changeset
33 chans[i] = c
kono
parents:
diff changeset
34 return int(i), int(i + 100)
kono
parents:
diff changeset
35 }
kono
parents:
diff changeset
36
kono
parents:
diff changeset
37 //export GoWait
kono
parents:
diff changeset
38 func GoWait(i C.int) {
kono
parents:
diff changeset
39 <-chans[i]
kono
parents:
diff changeset
40 chans[i] = nil
kono
parents:
diff changeset
41 }