v2 / vlib / os / signal_darwin.c.v
30 lines · 24 sloc · 853 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
19fn C.sigaddset(set &u32, signum i32) i32
20fn C.sigemptyset(set &u32)
21fn C.sigprocmask(how i32, set &u32, oldset &u32) i32
22
23fn signal_ignore_internal(args ...Signal) {
24 mask1 := u32(0)
25 C.sigemptyset(&mask1)
26 for arg in args {
27 C.sigaddset(&mask1, int(arg))
28 }
29 C.sigprocmask(C.SIG_BLOCK, &mask1, unsafe { nil })
30}
31