Skip to content

Commit c66b32a

Browse files
committed
reactor: deprecate at_destroy()
at_destroy() tasks are unordered with respect to each other, so are not very useful. They also consume a scheduling group. Since they are public, we can't remove them outright, but prepare by deprecating the public interface. Internal users are converted to a private interface.
1 parent 3f8bdf5 commit c66b32a

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

include/seastar/core/reactor.hh

+21-1
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ size_t scheduling_group_count();
129129

130130
void increase_thrown_exceptions_counter() noexcept;
131131

132+
template <typename Func>
133+
void at_destroy(Func&& func);
134+
132135
}
133136

134137
class io_queue;
@@ -162,6 +165,8 @@ private:
162165
class io_queue_submission_pollfn;
163166
class syscall_pollfn;
164167
class execution_stage_pollfn;
168+
template <typename Func>
169+
friend void internal::at_destroy(Func&&);
165170
friend class manual_clock;
166171
friend class file_data_source_impl; // for fstream statistics
167172
friend class internal::reactor_stall_sampler;
@@ -526,10 +531,16 @@ public:
526531
void at_exit(noncopyable_function<future<> ()> func);
527532

528533
template <typename Func>
534+
[[deprecated("Use app_template::run() for orderly shutdown")]]
529535
void at_destroy(Func&& func) {
536+
do_at_destroy(std::forward<Func>(func));
537+
}
538+
private:
539+
template <typename Func>
540+
void do_at_destroy(Func&& func) {
530541
_at_destroy_tasks->_q.push_back(make_task(default_scheduling_group(), std::forward<Func>(func)));
531542
}
532-
543+
public:
533544
task* current_task() const { return _current_task; }
534545
// If a task wants to resume a different task instead of returning control to the reactor,
535546
// it should set _current_task to the resumed task.
@@ -688,4 +699,13 @@ inline int hrtimer_signal() {
688699

689700
extern logger seastar_logger;
690701

702+
namespace internal {
703+
704+
template <typename Func>
705+
void at_destroy(Func&& func) {
706+
engine().do_at_destroy(std::forward<Func>(func));
707+
}
708+
709+
} // namespace internal
710+
691711
}

src/net/net.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ device::receive(std::function<future<> (packet)> next_packet) {
246246
void device::set_local_queue(std::unique_ptr<qp> dev) {
247247
assert(!_queues[this_shard_id()]);
248248
_queues[this_shard_id()] = dev.get();
249-
engine().at_destroy([dev = std::move(dev)] {});
249+
internal::at_destroy([dev = std::move(dev)] {});
250250
}
251251

252252

tests/unit/scheduling_group_test.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,8 @@ SEASTAR_THREAD_TEST_CASE(sg_key_constructor_exception_when_creating_new_key) {
392392
SEASTAR_THREAD_TEST_CASE(sg_create_with_destroy_tasks) {
393393
struct nada{};
394394

395-
engine().at_destroy([] {}); // nothing really
395+
// at_destroy() functionality is deprecated, but test until removed.
396+
internal::at_destroy([] {}); // nothing really
396397

397398
scheduling_group_key_config sg_conf = make_scheduling_group_key_config<nada>();
398399
scheduling_group_key_create(sg_conf).get();

0 commit comments

Comments
 (0)