mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-03 17:58:30 +00:00
Improve locks and signals
- Introduce fast spinlock API - Double rand64() perf w/ spinlock - Improve raise() on New Technology - Support gettid() across platforms - Implement SA_NODEFER on New Technology - Move the lock intrinsics into LIBC_INTRIN - Make SIGTRAP recoverable on New Technology - Block SIGCHLD in wait4() on New Technology - Add threading prototypes for XNU and FreeBSD - Rewrite abort() fixing its minor bugs on XNU/NT - Shave down a lot of the content in libc/bits/bits.h - Let signal handlers modify CPU registers on New Technology
This commit is contained in:
parent
f68f1789bd
commit
046c7ebd4a
110 changed files with 1514 additions and 876 deletions
|
@ -21,12 +21,20 @@
|
|||
#include "libc/sysv/consts/sa.h"
|
||||
|
||||
/**
|
||||
* Installs kernel interrupt handler.
|
||||
* Installs kernel interrupt handler, e.g.
|
||||
*
|
||||
* void GotCtrlC(int sig) { ... }
|
||||
* CHECK_NE(SIG_ERR, signal(SIGINT, GotCtrlC));
|
||||
*
|
||||
* @return old signal handler on success or SIG_ERR w/ errno
|
||||
* @note this function has BSD semantics, i.e. SA_RESTART
|
||||
* @see sigaction() which has more features
|
||||
*/
|
||||
sighandler_t(signal)(int sig, sighandler_t func) {
|
||||
struct sigaction sa_old, sa = {.sa_handler = func, .sa_flags = SA_RESTART};
|
||||
if ((sigaction)(sig, &sa, &sa_old) == -1) return SIG_ERR;
|
||||
return sa_old.sa_handler;
|
||||
struct sigaction old, sa = {.sa_handler = func, .sa_flags = SA_RESTART};
|
||||
if ((sigaction)(sig, &sa, &old) != -1) {
|
||||
return old.sa_handler;
|
||||
} else {
|
||||
return SIG_ERR;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue