-
Notifications
You must be signed in to change notification settings - Fork 3
/
signal_suppressor.cc
46 lines (34 loc) · 833 Bytes
/
signal_suppressor.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include "signal_suppressor.h"
#include <lace/try.h>
#include <cassert>
#include <cstddef>
#include <errno.h>
signal_suppressor::signal_suppressor(int s)
: signal(s)
, mask(signal)
{ suppress(); }
signal_suppressor::~signal_suppressor() { restore(); }
void
signal_suppressor::suppress() {
if ((was_pending = signal_set().pending().has(signal)))
return;
if (!signal_set().current().has(signal))
blocked.add(signal).block();
}
void
signal_suppressor::restore() {
if (was_pending)
return;
if (signal_set().pending().has(signal)) {
struct timespec ts;
ts.tv_sec = 0;
ts.tv_nsec = 0;
while (TRY_ERR(EINTR, sigtimedwait, &mask, NULL, &ts) < 0) { }
assert(!signal_set().pending().has(signal));
}
if (blocked.has(signal)) {
blocked.unblock();
blocked.del(signal);
}
}
//