v2 / vlib / os / signal_linux.c.v
35 lines · 28 sloc · 967 bytes · a87a4d73b9ab25cfff0822f4e94cf2a2d9e64323
Raw
1@[has_globals]
2module os
3
4#flag -lpthread
5#include <signal.h>
6
7fn C.pthread_self() usize
8
9// g_main_thread_id and is_main_thread can be used to determine if the current thread is the main thread.
10// if need to get the tid of the main thread, can use the global variable g_main_thread_id
11// instead of using thread_id() every time.
12__global g_main_thread_id = u64(C.pthread_self())
13
14// is_main_thread returns whether the current thread is the main thread.
15pub fn is_main_thread() bool {
16 return g_main_thread_id == u64(C.pthread_self())
17}
18
19@[typedef]
20struct C.sigset_t {}
21
22fn C.sigaddset(set &C.sigset_t, signum i32) i32
23fn C.sigemptyset(set &C.sigset_t)
24fn C.sigprocmask(how i32, set &C.sigset_t, oldset &C.sigset_t) i32
25
26fn signal_ignore_internal(args ...Signal) {
27 $if !android && !macos && !openbsd {
28 mask1 := C.sigset_t{}
29 C.sigemptyset(&mask1)
30 for arg in args {
31 C.sigaddset(&mask1, int(arg))
32 }
33 C.sigprocmask(C.SIG_BLOCK, &mask1, unsafe { nil })
34 }
35}
36