github.com/MangoDowner/go-gm@v0.0.0-20180818020936-8baa2bd4408c/misc/cgo/test/sigprocmask.c (about)

     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  // +build !windows
     6  
     7  #include <signal.h>
     8  #include <stdlib.h>
     9  #include <pthread.h>
    10  #include <stdio.h>
    11  #include <unistd.h>
    12  
    13  extern void IntoGoAndBack();
    14  
    15  int CheckBlocked() {
    16  	sigset_t mask;
    17  	sigprocmask(SIG_BLOCK, NULL, &mask);
    18  	return sigismember(&mask, SIGIO);
    19  }
    20  
    21  static void* sigthreadfunc(void* unused) {
    22  	sigset_t mask;
    23  	sigemptyset(&mask);
    24  	sigaddset(&mask, SIGIO);
    25  	sigprocmask(SIG_BLOCK, &mask, NULL);
    26  	IntoGoAndBack();
    27  	return NULL;
    28  }
    29  
    30  int RunSigThread() {
    31  	pthread_t thread;
    32  	int r;
    33  
    34  	r = pthread_create(&thread, NULL, &sigthreadfunc, NULL);
    35  	if (r != 0)
    36  		return r;
    37  	return pthread_join(thread, NULL);
    38  }