Add sighupint topic

This corresponds to SIGHUP and SIGINT. This will be used to break out of
process_mark_finished_children().
This commit is contained in:
ridiculousfish 2019-02-14 20:55:43 -08:00
parent fc9d238642
commit a4dc04a28e
4 changed files with 16 additions and 7 deletions

View file

@ -31,6 +31,10 @@ class enum_set_t : private std::bitset<enum_count<T>()> {
/*implicit*/ enum_set_t(T v) { set(v); }
/*implicit*/ enum_set_t(std::initializer_list<T> vs) {
for (T v : vs) set(v);
}
static enum_set_t from_raw(unsigned long v) { return enum_set_t{v}; }
unsigned long to_raw() const { return super::to_ulong(); }

View file

@ -5102,14 +5102,15 @@ static void test_topic_monitor_torture() {
say(L"Torture-testing topic monitor");
topic_monitor_t monitor;
const size_t thread_count = 64;
constexpr auto t = topic_t::sigchld;
constexpr auto t1 = topic_t::sigchld;
constexpr auto t2 = topic_t::sighupint;
std::vector<generation_list_t> gens;
gens.resize(thread_count, generation_list_t{});
std::atomic<uint32_t> post_count{};
for (auto &gen : gens) {
gen = monitor.current_generations();
post_count += 1;
monitor.post(t);
monitor.post(t1);
}
std::atomic<uint32_t> completed{};
@ -5119,9 +5120,10 @@ static void test_topic_monitor_torture() {
[&](size_t i) {
for (size_t j = 0; j < (1 << 11); j++) {
auto before = gens[i];
auto changed = monitor.check(&gens[i], topic_set_t{t}, true /* wait */);
do_test(before[t] < gens[i][t]);
do_test(gens[i][t] <= post_count);
auto changed = monitor.check(&gens[i], topic_set_t{t1, t2}, true /* wait */);
do_test(before[t1] < gens[i][t1]);
do_test(gens[i][t1] <= post_count);
do_test(gens[i][t2] == 0);
}
auto amt = completed.fetch_add(1, std::memory_order_relaxed);
},
@ -5130,7 +5132,7 @@ static void test_topic_monitor_torture() {
while (completed.load(std::memory_order_relaxed) < thread_count) {
post_count += 1;
monitor.post(t);
monitor.post(t1);
}
for (auto &t : threads) t.join();
}

View file

@ -231,6 +231,7 @@ static void handle_hup(int sig, siginfo_t *info, void *context) {
} else {
reader_exit(1, 1);
}
topic_monitor_t::principal().post(topic_t::sighupint);
}
/// Handle sigterm. The only thing we do is restore the front process ID, then die.
@ -249,6 +250,7 @@ static void handle_int(int sig, siginfo_t *info, void *context) {
if (reraise_if_forked_child(sig)) return;
reader_handle_sigint();
default_handler(sig, info, context);
topic_monitor_t::principal().post(topic_t::sighupint);
}
/// Non-interactive ^C handler.

View file

@ -35,7 +35,8 @@
/// The list of topics that may be observed.
enum class topic_t : uint8_t {
sigchld, // Corresponds to SIGCHLD signal.
sigchld, // Corresponds to SIGCHLD signal.
sighupint, // Corresponds to both SIGHUP and SIGINT signals.
COUNT
};