]> Cypherpunks.ru repositories - gostls13.git/blob - misc/cgo/testcarchive/testdata/libgo4/libgo4.go
c81d3af4ea3b97e3b81d9f5d84a1f7ecd642981d
[gostls13.git] / misc / cgo / testcarchive / testdata / libgo4 / libgo4.go
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 //
29 //export GoCatchSIGIO
30 func GoCatchSIGIO() {
31         c := make(chan os.Signal, 1)
32         signal.Notify(c, syscall.SIGIO)
33         go func() {
34                 for range c {
35                         atomic.AddInt32(&sigioCount, 1)
36                 }
37         }()
38 }
39
40 // Raise SIGIO.
41 //
42 //export GoRaiseSIGIO
43 func GoRaiseSIGIO(p *C.pthread_t) {
44         C.CRaiseSIGIO(p)
45 }
46
47 // Return the number of SIGIO signals seen.
48 //
49 //export SIGIOCount
50 func SIGIOCount() C.int {
51         return C.int(atomic.LoadInt32(&sigioCount))
52 }
53
54 func main() {
55 }