Debian Codegraph @

libgo/misc/cgo/testcarchive/testdata/libgo4/libgo4.go

raw
1 // Copyright 2015 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 /*
8 #include <signal.h>
9 #include <pthread.h>
10
11 // Raise SIGIO.
12 static void CRaiseSIGIO(pthread_t* p) {
13 pthread_kill(*p, SIGIO);
14 }
15 */
16 import "C"
17
18 import (
19 "os"
20 "os/signal"
21 "sync/atomic"
22 "syscall"
23 )
24
25 var sigioCount int32
26
27 // Catch SIGIO.
28 //export GoCatchSIGIO
29 func GoCatchSIGIO() {
30 c := make(chan os.Signal, 1)
31 signal.Notify(c, syscall.SIGIO)
32 go func() {
33 for range c {
34 atomic.AddInt32(&sigioCount, 1)
35 }
36 }()
37 }
38
39 // Raise SIGIO.
40 //export GoRaiseSIGIO
41 func GoRaiseSIGIO(p *C.pthread_t) {
42 C.CRaiseSIGIO(p)
43 }
44
45 // Return the number of SIGIO signals seen.
46 //export SIGIOCount
47 func SIGIOCount() C.int {
48 return C.int(atomic.LoadInt32(&sigioCount))
49 }
50
51 func main() {
52 }