| 1 |
// Copyright 2010 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 main |
| 6 |
|
| 7 |
// #include "life.h" |
| 8 |
import "C" |
| 9 |
|
| 10 |
import "unsafe" |
| 11 |
|
| 12 |
func Run(gen, x, y int, a []int32) { |
| 13 |
n := make([]int32, x*y) |
| 14 |
for i := 0; i < gen; i++ { |
| 15 |
C.Step(C.int(x), C.int(y), (*C.int)(unsafe.Pointer(&a[0])), (*C.int)(unsafe.Pointer(&n[0]))) |
| 16 |
copy(a, n) |
| 17 |
} |
| 18 |
} |
| 19 |
|
| 20 |
// Keep the channels visible from Go. |
| 21 |
var chans [4]chan bool |
| 22 |
|
| 23 |
//export GoStart |
| 24 |
// Double return value is just for testing. |
| 25 |
func GoStart(i, xdim, ydim, xstart, xend, ystart, yend C.int, a *C.int, n *C.int) (int, int) { |
| 26 |
c := make(chan bool, int(C.MYCONST)) |
| 27 |
go func() { |
| 28 |
C.DoStep(xdim, ydim, xstart, xend, ystart, yend, a, n) |
| 29 |
c <- true |
| 30 |
}() |
| 31 |
chans[i] = c |
| 32 |
return int(i), int(i + 100) |
| 33 |
} |
| 34 |
|
| 35 |
//export GoWait |
| 36 |
func GoWait(i C.int) { |
| 37 |
<-chans[i] |
| 38 |
chans[i] = nil |
| 39 |
} |