| 1 | @[has_globals] |
| 2 | module os |
| 3 | |
| 4 | #flag -lpthread |
| 5 | #include <signal.h> |
| 6 | |
| 7 | fn 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. |
| 15 | pub fn is_main_thread() bool { |
| 16 | return g_main_thread_id == u64(C.pthread_self()) |
| 17 | } |
| 18 | |
| 19 | @[typedef] |
| 20 | struct C.sigset_t {} |
| 21 | |
| 22 | fn C.sigaddset(set &C.sigset_t, signum i32) i32 |
| 23 | fn C.sigemptyset(set &C.sigset_t) |
| 24 | fn C.sigprocmask(how i32, set &C.sigset_t, oldset &C.sigset_t) i32 |
| 25 | |
| 26 | fn 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 | |