mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-16 15:04:05 +00:00
Mild refactoring of how received signals are stored
No functional change here, just some cleanup.
This commit is contained in:
parent
ce2064d8b6
commit
31567cea63
1 changed files with 7 additions and 11 deletions
|
@ -33,7 +33,7 @@ class pending_signals_t {
|
||||||
std::atomic<uint32_t> counter_{0};
|
std::atomic<uint32_t> counter_{0};
|
||||||
|
|
||||||
/// List of pending signals.
|
/// List of pending signals.
|
||||||
std::array<std::atomic<bool>, SIGNAL_COUNT> received_{};
|
std::array<relaxed_atomic_bool_t, SIGNAL_COUNT> received_{};
|
||||||
|
|
||||||
/// The last counter visible in acquire_pending().
|
/// The last counter visible in acquire_pending().
|
||||||
/// This is not accessed from a signal handler.
|
/// This is not accessed from a signal handler.
|
||||||
|
@ -52,7 +52,7 @@ class pending_signals_t {
|
||||||
void mark(int which) {
|
void mark(int which) {
|
||||||
if (which >= 0 && static_cast<size_t>(which) < received_.size()) {
|
if (which >= 0 && static_cast<size_t>(which) < received_.size()) {
|
||||||
// Must mark our received first, then pending.
|
// Must mark our received first, then pending.
|
||||||
received_[which].store(true, std::memory_order_relaxed);
|
received_[which] = true;
|
||||||
uint32_t count = counter_.load(std::memory_order_relaxed);
|
uint32_t count = counter_.load(std::memory_order_relaxed);
|
||||||
counter_.store(1 + count, std::memory_order_release);
|
counter_.store(1 + count, std::memory_order_release);
|
||||||
}
|
}
|
||||||
|
@ -68,18 +68,14 @@ class pending_signals_t {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
// The signal count has changed. Store the new counter and fetch all the signals that are
|
// The signal count has changed. Store the new counter and fetch all set signals.
|
||||||
// set.
|
|
||||||
*current = count;
|
*current = count;
|
||||||
std::bitset<SIGNAL_COUNT> result{};
|
std::bitset<SIGNAL_COUNT> result{};
|
||||||
uint32_t bit = 0;
|
for (size_t i = 0; i < NSIG; i++) {
|
||||||
for (auto &signal : received_) {
|
if (received_[i]) {
|
||||||
bool val = signal.load(std::memory_order_relaxed);
|
result.set(i);
|
||||||
if (val) {
|
received_[i] = false;
|
||||||
result.set(bit);
|
|
||||||
signal.store(false, std::memory_order_relaxed);
|
|
||||||
}
|
}
|
||||||
bit++;
|
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue