2 * Copyright (C) 2012-2020 all contributors <cmogstored-public@yhbt.net>
3 * License: GPL-3.0+ <https://www.gnu.org/licenses/gpl-3.0.txt>
5 #include "cmogstored.h"
8 * we block signals in pool threads, only the main thread receives signals
11 static sigset_t fullset
;
12 sigset_t mog_emptyset
;
14 __attribute__((constructor
)) static void sig_init(void)
16 CHECK(int, 0, sigfillset(&fullset
));
17 CHECK(int, 0, sigemptyset(&mog_emptyset
));
20 void mog_intr_disable(void)
22 CHECK(int, 0, pthread_sigmask(SIG_SETMASK
, &fullset
, NULL
));
25 void mog_intr_enable(void)
27 CHECK(int, 0, pthread_sigmask(SIG_SETMASK
, &mog_emptyset
, NULL
));
30 static int sleeper(struct timespec
*tsp
, const sigset_t
*sigmask
)
35 * pselect is a cancellation point,
36 * ppoll is not POSIX and is only a cancellation point on glibc.
38 if (pselect(0, NULL
, NULL
, NULL
, tsp
, sigmask
) < 0) {
40 assert((err
== EINTR
|| err
== ENOMEM
) &&
41 "BUG in pselect usage");
46 /* thread-safe, interruptible sleep, negative seconds -> sleep forever */
47 int mog_sleep(long seconds
)
60 return sleeper(tsp
, &mog_emptyset
);