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 5package main 6 7/* 8#include <signal.h> 9#include <pthread.h> 10 11// Raise SIGIO. 12static void CRaiseSIGIO(pthread_t* p) { 13 pthread_kill(*p, SIGIO); 14} 15*/ 16import "C" 17 18import ( 19 "os" 20 "os/signal" 21 "sync/atomic" 22 "syscall" 23) 24 25var sigioCount int32 26 27// Catch SIGIO. 28// 29//export GoCatchSIGIO 30func 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 43func GoRaiseSIGIO(p *C.pthread_t) { 44 C.CRaiseSIGIO(p) 45} 46 47// Return the number of SIGIO signals seen. 48// 49//export SIGIOCount 50func SIGIOCount() C.int { 51 return C.int(atomic.LoadInt32(&sigioCount)) 52} 53 54func main() { 55} 56