Files
scylladb/utils/composite_abort_source.hh
Avi Kivity aa1270a00c treewide: change assert() to SCYLLA_ASSERT()
assert() is traditionally disabled in release builds, but not in
scylladb. This hasn't caused problems so far, but the latest abseil
release includes a commit [1] that causes a 1000 insn/op regression when
NDEBUG is not defined.

Clearly, we must move towards a build system where NDEBUG is defined in
release builds. But we can't just define it blindly without vetting
all the assert() calls, as some were written with the expectation that
they are enabled in release mode.

To solve the conundrum, change all assert() calls to a new SCYLLA_ASSERT()
macro in utils/assert.hh. This macro is always defined and is not conditional
on NDEBUG, so we can later (after vetting Seastar) enable NDEBUG in release
mode.

[1] 66ef711d68

Closes scylladb/scylladb#20006
2024-08-05 08:23:35 +03:00

26 lines
900 B
C++

#include <seastar/core/abort_source.hh>
#include "utils/assert.hh"
#include "utils/small_vector.hh"
#include "seastarx.hh"
namespace utils {
// A facility to combine several abort_source-s and expose them as a single abort_source.
// The combined abort_source is aborted whenever any of the added abort_sources is aborted.
// Typical use case: there are several sources of abort signal (e.g. timeout and node shutdown)
// and we what some routine to be aborted on any of them.
class composite_abort_source {
abort_source _as;
utils::small_vector<abort_source::subscription, 2> _subscriptions;
public:
void add(abort_source& as) {
as.check();
auto sub = as.subscribe([this]() noexcept { _as.request_abort(); });
SCYLLA_ASSERT(sub);
_subscriptions.push_back(std::move(*sub));
}
abort_source& abort_source() noexcept {
return _as;
}
};
}