diff options
author | Peter Hutterer <peter.hutterer@who-t.net> | 2012-06-22 13:02:40 +1000 |
---|---|---|
committer | Peter Hutterer <peter.hutterer@who-t.net> | 2012-07-03 15:56:33 +1000 |
commit | 6bf356ef2831baeccd7a650ed3fde0831e33c6c0 (patch) | |
tree | 3148f6ef0df6da8ea074ba46c7b8d80f33e20fd2 /os | |
parent | 9f1edced9abc066f0ba47672d006fe50fb206371 (diff) |
os: add OsBlockSIGIO and OsReleaseSIGIO
Let the dix be in charge of changing the sigprocmask so we only have one
entity that changes it.
Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
Reviewed-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'os')
-rw-r--r-- | os/utils.c | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/os/utils.c b/os/utils.c index 3a1ef9303..55f58b962 100644 --- a/os/utils.c +++ b/os/utils.c @@ -1165,15 +1165,15 @@ OsBlockSignals(void) if (BlockedSignalCount++ == 0) { sigset_t set; +#ifdef SIGIO + OsBlockSIGIO(); +#endif sigemptyset(&set); sigaddset(&set, SIGALRM); sigaddset(&set, SIGVTALRM); #ifdef SIGWINCH sigaddset(&set, SIGWINCH); #endif -#ifdef SIGIO - sigaddset(&set, SIGIO); -#endif sigaddset(&set, SIGTSTP); sigaddset(&set, SIGTTIN); sigaddset(&set, SIGTTOU); @@ -1183,12 +1183,60 @@ OsBlockSignals(void) #endif } +#ifdef SIG_BLOCK +static sig_atomic_t sigio_blocked; +#endif + +/** + * returns zero if this call caused SIGIO to be blocked now, non-zero if it + * was already blocked by a previous call to this function. + */ +int +OsBlockSIGIO(void) +{ +#ifdef SIGIO +#ifdef SIG_BLOCK + if (sigio_blocked++ == 0) { + sigset_t set, old; + int ret; + + sigemptyset(&set); + sigaddset(&set, SIGIO); + sigprocmask(SIG_BLOCK, &set, &old); + ret = sigismember(&old, SIGIO); + return ret; + } else + return 1; +#endif +#endif +} + +void +OsReleaseSIGIO(void) +{ +#ifdef SIGIO +#ifdef SIG_BLOCK + if (--sigio_blocked == 0) { + sigset_t set; + + sigemptyset(&set); + sigaddset(&set, SIGIO); + sigprocmask(SIG_UNBLOCK, &set, NULL); + } else if (sigio_blocked < 0) { + BUG_WARN(sigio_blocked < 0); + sigio_blocked = 0; + } +#endif +#endif +} + void OsReleaseSignals(void) { #ifdef SIG_BLOCK if (--BlockedSignalCount == 0) { sigprocmask(SIG_SETMASK, &PreviousSignalMask, 0); + OsReleaseSIGIO(); } #endif } |