From 2a86b03a3f141e7bc727a98a803df3c7c10b9b0b Mon Sep 17 00:00:00 2001 From: Nikita Nikolaenko <6870920@gmail.com> Date: Wed, 3 Aug 2022 15:28:14 +0200 Subject: [PATCH] Explicit definition of all ctrs, operator= and dstrs To comply with the rule C.21 of C++ Core Guidelines: https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#c21-if-you-define-or-delete-any-copy-move-or-destructor-function-define-or-delete-them-all --- eventuals/builder.h | 38 +++++++++++++++++++++++++++++++ eventuals/callback.h | 35 +++++++++++++++++++++-------- eventuals/concurrent-ordered.h | 10 +++++++++ eventuals/concurrent.h | 27 ++++++++++++++++++++-- eventuals/do-all.h | 14 ++++++++++++ eventuals/event-loop.h | 31 +++++++++++++++++++++++-- eventuals/eventual.h | 5 +++++ eventuals/flat-map.h | 4 ++++ eventuals/generator.h | 8 +++++-- eventuals/http.cc | 6 +++++ eventuals/http.h | 19 ++++++++++++++++ eventuals/interrupt.h | 5 +++++ eventuals/lazy.h | 7 ++++++ eventuals/lock.h | 21 +++++++++++++++++ eventuals/loop.h | 5 +++++ eventuals/pipe.h | 6 +++++ eventuals/range.h | 4 ++++ eventuals/repeat.h | 4 ++++ eventuals/rsa.h | 8 +++++++ eventuals/scheduler.cc | 8 +++++++ eventuals/scheduler.h | 41 +++++++++++++++++++++++----------- eventuals/semaphore.h | 8 ++++--- eventuals/static-thread-pool.h | 30 ++++++++++++++++++++----- eventuals/stream.h | 3 +++ eventuals/take.h | 12 ++++++++-- eventuals/task.h | 5 +++++ eventuals/terminal.h | 8 +++++-- eventuals/type-erased-stream.h | 9 ++++++++ eventuals/x509.h | 8 +++++++ 29 files changed, 349 insertions(+), 40 deletions(-) diff --git a/eventuals/builder.h b/eventuals/builder.h index e89b6210..a1318abd 100644 --- a/eventuals/builder.h +++ b/eventuals/builder.h @@ -18,6 +18,14 @@ class Field; template class Field { public: + Field() = default; + + Field(const Field&) = default; + Field(Field&&) noexcept = default; + + Field& operator=(const Field&) = default; + Field& operator=(Field&&) noexcept = default; + virtual ~Field() = default; template @@ -33,6 +41,12 @@ class Field { Field(Value_ value) : value_(std::move(value)) {} + Field(const Field&) = default; + Field(Field&&) noexcept = default; + + Field& operator=(const Field&) = default; + Field& operator=(Field&&) noexcept = default; + virtual ~Field() = default; auto& value() & { @@ -77,8 +91,12 @@ class FieldWithDefault final : public Field { FieldWithDefault(Value&& value) : default_(std::forward(value)) {} + FieldWithDefault(const FieldWithDefault&) = delete; FieldWithDefault(FieldWithDefault&&) noexcept = default; + FieldWithDefault& operator=(const FieldWithDefault&) = delete; + FieldWithDefault& operator=(FieldWithDefault&&) noexcept = delete; + ~FieldWithDefault() override = default; template @@ -124,8 +142,12 @@ class FieldWithDefault final : public Field { FieldWithDefault(Value&& value) : Field(std::forward(value)) {} + FieldWithDefault(const FieldWithDefault&) = delete; FieldWithDefault(FieldWithDefault&&) noexcept = default; + FieldWithDefault& operator=(const FieldWithDefault&) = delete; + FieldWithDefault& operator=(FieldWithDefault&&) noexcept = delete; + ~FieldWithDefault() override = default; }; @@ -143,8 +165,12 @@ class RepeatedField final : public Field { RepeatedField(Value&& value) : default_(std::forward(value)) {} + RepeatedField(const RepeatedField&) = delete; RepeatedField(RepeatedField&&) noexcept = default; + RepeatedField& operator=(const RepeatedField&) = delete; + RepeatedField& operator=(RepeatedField&&) noexcept = delete; + ~RepeatedField() override = default; template @@ -190,8 +216,12 @@ class RepeatedField final : public Field { RepeatedField(Value&& value) : Field(std::forward(value)) {} + RepeatedField(const RepeatedField&) = delete; RepeatedField(RepeatedField&&) noexcept = default; + RepeatedField& operator=(const RepeatedField&) = delete; + RepeatedField& operator=(RepeatedField&&) noexcept = delete; + ~RepeatedField() override = default; template @@ -205,6 +235,14 @@ class RepeatedField final : public Field { class Builder { public: + Builder() = default; + + Builder(const Builder&) = default; + Builder(Builder&&) noexcept = default; + + Builder& operator=(const Builder&) = default; + Builder& operator=(Builder&&) noexcept = default; + virtual ~Builder() = default; protected: diff --git a/eventuals/callback.h b/eventuals/callback.h index c8a9c5f9..8d009463 100644 --- a/eventuals/callback.h +++ b/eventuals/callback.h @@ -35,6 +35,18 @@ struct Callback final { this->operator=(std::move(f)); } + Callback(const Callback&) = delete; + + Callback(Callback&& that) noexcept { + if (that.base_ != nullptr) { + base_ = that.base_->Move(&storage_); + + // Set 'base_' to nullptr so we only destruct once. + that.base_ = nullptr; + } + } + + Callback& operator=(const Callback&) = delete; Callback& operator=(Callback&& that) noexcept { if (this == &that) { return *this; @@ -77,15 +89,6 @@ struct Callback final { return *this; } - Callback(Callback&& that) noexcept { - if (that.base_ != nullptr) { - base_ = that.base_->Move(&storage_); - - // Set 'base_' to nullptr so we only destruct once. - that.base_ = nullptr; - } - } - ~Callback() { if (base_ != nullptr) { base_->~Base(); @@ -102,6 +105,14 @@ struct Callback final { } struct Base { + Base() = default; + + Base(const Base&) = default; + Base(Base&&) noexcept = default; + + Base& operator=(const Base&) = default; + Base& operator=(Base&&) noexcept = default; + virtual ~Base() = default; virtual R Invoke(Args... args) = 0; @@ -114,6 +125,12 @@ struct Callback final { Handler(F f) : f_(std::move(f)) {} + Handler(const Handler&) = default; + Handler(Handler&&) noexcept = default; + + Handler& operator=(const Handler&) = default; + Handler& operator=(Handler&&) noexcept = default; + ~Handler() override = default; R Invoke(Args... args) override { diff --git a/eventuals/concurrent-ordered.h b/eventuals/concurrent-ordered.h index 67b6028c..5ed97e8c 100644 --- a/eventuals/concurrent-ordered.h +++ b/eventuals/concurrent-ordered.h @@ -26,8 +26,12 @@ struct _ReorderAdaptor final { Continuation(K_ k) : k_(std::move(k)) {} + Continuation(const Continuation&) = delete; Continuation(Continuation&& that) noexcept = default; + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&&) noexcept = delete; + ~Continuation() override = default; void Begin(TypeErasedStream& stream) { @@ -150,6 +154,12 @@ struct _ConcurrentOrderedAdaptor final { Continuation(K_ k) : k_(std::move(k)) {} + Continuation(const Continuation&) = default; + Continuation(Continuation&&) noexcept = default; + + Continuation& operator=(const Continuation&) = default; + Continuation& operator=(Continuation&&) noexcept = default; + ~Continuation() override = default; void Begin(TypeErasedStream& stream) { diff --git a/eventuals/concurrent.h b/eventuals/concurrent.h index 0d057646..566d52a6 100644 --- a/eventuals/concurrent.h +++ b/eventuals/concurrent.h @@ -70,6 +70,20 @@ struct _Concurrent final { // that have completed but haven't yet been pruned (see // 'CreateOrReuseFiber()'). struct TypeErasedFiber { + TypeErasedFiber() = default; + + // Constructors and assignment operators are deleted, because + // 'Interrupt' class has std::atomic (which is not copyable/moveable), + // and doesn't provide its own copy/move constructors/assignment + // operators. + TypeErasedFiber(const TypeErasedFiber&) = delete; + TypeErasedFiber(TypeErasedFiber&&) noexcept = delete; + + TypeErasedFiber& operator=(const TypeErasedFiber&) = delete; + TypeErasedFiber& operator=(TypeErasedFiber&&) = delete; + + virtual ~TypeErasedFiber() = default; + void Reuse() { done = false; // Need to reinitialize the interrupt so that the @@ -79,8 +93,6 @@ struct _Concurrent final { new (&interrupt) class Interrupt(); } - virtual ~TypeErasedFiber() = default; - // A fiber indicates it is done with this boolean. bool done = false; @@ -432,6 +444,12 @@ struct _Concurrent final { Adaptor(F_ f) : f_(std::move(f)) {} + Adaptor(const Adaptor&) = default; + Adaptor(Adaptor&&) noexcept = default; + + Adaptor& operator=(const Adaptor&) = default; + Adaptor& operator=(Adaptor&&) noexcept = default; + ~Adaptor() override = default; // Our typeful fiber includes the continuation 'K' that we'll @@ -585,11 +603,16 @@ struct _Concurrent final { : adaptor_(std::move(f)), k_(std::move(k)) {} + Continuation(const Continuation&) = delete; + // NOTE: explicit move-constructor because of 'std::atomic_flag'. Continuation(Continuation&& that) noexcept : adaptor_(std::move(that.adaptor_.f_)), k_(std::move(that.k_)) {} + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&&) noexcept = delete; + ~Continuation() override = default; void Begin(TypeErasedStream& stream) { diff --git a/eventuals/do-all.h b/eventuals/do-all.h index ac6baf96..8bf2c62e 100644 --- a/eventuals/do-all.h +++ b/eventuals/do-all.h @@ -21,6 +21,8 @@ struct _DoAll final { : k_(k), interrupt_(interrupt) {} + Adaptor(const Adaptor&) = delete; + Adaptor(Adaptor&& that) noexcept : k_(that.k_), interrupt_(that.interrupt_) { @@ -28,6 +30,11 @@ struct _DoAll final { << "moving after starting is illegal"; } + Adaptor& operator=(const Adaptor&) = delete; + Adaptor& operator=(Adaptor&&) noexcept = delete; + + ~Adaptor() = default; + K_& k_; Interrupt& interrupt_; @@ -190,6 +197,8 @@ struct _DoAll final { : eventuals_(std::move(eventuals)), k_(std::move(k)) {} + Continuation(const Continuation&) = delete; + Continuation(Continuation&& that) noexcept : eventuals_(std::move(that.eventuals_)), adaptor_(std::move(that.adaptor_)), @@ -197,6 +206,11 @@ struct _DoAll final { handler_(std::move(that.handler_)), k_(std::move(that.k_)) {} + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&&) noexcept = delete; + + ~Continuation() = default; + template void Start(Args&&...) { adaptor_.emplace(k_, interrupt_); diff --git a/eventuals/event-loop.h b/eventuals/event-loop.h index 809c7b00..96a282fd 100644 --- a/eventuals/event-loop.h +++ b/eventuals/event-loop.h @@ -153,11 +153,17 @@ class EventLoop final : public Scheduler { class Clock final : public stout::enable_borrowable_from_this { public: - Clock(const Clock&) = delete; - Clock(EventLoop& loop) : loop_(loop) {} + Clock(const Clock&) = delete; + Clock(Clock&&) noexcept = delete; + + Clock& operator=(const Clock&) = delete; + Clock& operator=(Clock&&) noexcept = delete; + + ~Clock() override = default; + std::chrono::nanoseconds Now(); auto Timer(std::chrono::nanoseconds nanoseconds); @@ -204,6 +210,8 @@ class EventLoop final : public Scheduler { interrupt_context_(&clock_->loop(), "Timer (interrupt)"), k_(std::move(k)) {} + Continuation(const Continuation&) = delete; + Continuation(Continuation&& that) noexcept : clock_(std::move(that.clock_)), nanoseconds_(std::move(that.nanoseconds_)), @@ -214,6 +222,9 @@ class EventLoop final : public Scheduler { CHECK(!handler_); } + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&&) noexcept = delete; + ~Continuation() { CHECK(!started_ || closed_); } @@ -462,7 +473,13 @@ class EventLoop final : public Scheduler { static void ConstructDefaultAndRunForeverDetached(); EventLoop(); + EventLoop(const EventLoop&) = delete; + EventLoop(EventLoop&&) noexcept = delete; + + EventLoop& operator=(const EventLoop&) = delete; + EventLoop& operator=(EventLoop&&) noexcept = delete; + ~EventLoop() override; void RunForever(); @@ -555,6 +572,8 @@ class EventLoop final : public Scheduler { interrupt_context_(&loop, "WaitForSignal (interrupt)"), k_(std::move(k)) {} + Continuation(const Continuation&) = delete; + Continuation(Continuation&& that) noexcept : loop_(that.loop_), signum_(that.signum_), @@ -565,6 +584,9 @@ class EventLoop final : public Scheduler { CHECK(!handler_); } + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&&) noexcept = delete; + ~Continuation() { CHECK(!started_ || closed_); } @@ -775,6 +797,8 @@ class EventLoop final : public Scheduler { interrupt_context_(&loop, "Poll (interrupt)"), k_(std::move(k)) {} + Continuation(const Continuation&) = delete; + Continuation(Continuation&& that) noexcept : loop_(that.loop_), fd_(that.fd_), @@ -786,6 +810,9 @@ class EventLoop final : public Scheduler { CHECK(!handler_); } + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&&) noexcept = delete; + ~Continuation() { CHECK(!started_ || closed_); } diff --git a/eventuals/eventual.h b/eventuals/eventual.h index 1cb98793..a66f83d5 100644 --- a/eventuals/eventual.h +++ b/eventuals/eventual.h @@ -80,8 +80,11 @@ struct _Eventual { stop_(std::move(stop)), k_(std::move(k)) {} + Continuation(const Continuation&) = delete; Continuation(Continuation&& that) noexcept = default; + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&& that) noexcept { if (this == &that) { return *this; @@ -97,6 +100,8 @@ struct _Eventual { return *this; } + ~Continuation() = default; + template void Start(Args&&... args) { static_assert( diff --git a/eventuals/flat-map.h b/eventuals/flat-map.h index 1e243ed0..9b9f46b0 100644 --- a/eventuals/flat-map.h +++ b/eventuals/flat-map.h @@ -61,8 +61,12 @@ struct _FlatMap final { : f_(std::move(f)), k_(std::move(k)) {} + Continuation(const Continuation&) = delete; Continuation(Continuation&& that) noexcept = default; + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&&) noexcept = delete; + ~Continuation() override = default; void Begin(TypeErasedStream& stream) { diff --git a/eventuals/generator.h b/eventuals/generator.h index 1764825b..fd82662b 100644 --- a/eventuals/generator.h +++ b/eventuals/generator.h @@ -456,9 +456,13 @@ struct _Generator final { }; } - ~Composable() = default; + Composable(const Composable&) = delete; + Composable(Composable&&) noexcept = default; + + Composable& operator=(const Composable&) = delete; + Composable& operator=(Composable&&) noexcept = delete; - Composable(Composable&& that) noexcept = default; + ~Composable() = default; template auto k(K k) && { diff --git a/eventuals/http.cc b/eventuals/http.cc index 5e4e7ad8..ff5ca007 100644 --- a/eventuals/http.cc +++ b/eventuals/http.cc @@ -12,6 +12,12 @@ class CURLGlobalInitializer final { CHECK_EQ(curl_global_init(CURL_GLOBAL_ALL), 0); } + CURLGlobalInitializer(const CURLGlobalInitializer&) = default; + CURLGlobalInitializer(CURLGlobalInitializer&&) noexcept = default; + + CURLGlobalInitializer& operator=(const CURLGlobalInitializer&) = default; + CURLGlobalInitializer& operator=(CURLGlobalInitializer&&) noexcept = default; + ~CURLGlobalInitializer() { curl_global_cleanup(); } diff --git a/eventuals/http.h b/eventuals/http.h index 017628a0..525a5e65 100644 --- a/eventuals/http.h +++ b/eventuals/http.h @@ -100,6 +100,12 @@ template < bool has_headers_> class Request::_Builder final : public builder::Builder { public: + _Builder(const _Builder&) = default; + _Builder(_Builder&&) noexcept = default; + + _Builder& operator=(const _Builder&) = default; + _Builder& operator=(_Builder&&) noexcept = default; + ~_Builder() override = default; auto uri(std::string&& uri) && { @@ -289,6 +295,8 @@ struct Response final { Response& operator=(const Response&) = default; Response& operator=(Response&&) = default; + ~Response() = default; + const auto& code() const { return code_; } @@ -351,6 +359,12 @@ class Client final { template class Client::_Builder final : public builder::Builder { public: + _Builder(const _Builder&) = default; + _Builder(_Builder&&) noexcept = default; + + _Builder& operator=(const _Builder&) = default; + _Builder& operator=(_Builder&&) noexcept = default; + ~_Builder() override = default; auto verify_peer(bool verify_peer) && { @@ -445,6 +459,8 @@ struct _HTTP final { interrupt_context_(&loop_, "HTTP (interrupt)"), k_(std::move(k)) {} + Continuation(const Continuation&) = delete; + Continuation(Continuation&& that) noexcept : loop_(that.loop_), request_(std::move(that.request_)), @@ -459,6 +475,9 @@ struct _HTTP final { CHECK(!handler_); } + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&&) noexcept = delete; + ~Continuation() { CHECK(!started_ || closed_); } diff --git a/eventuals/interrupt.h b/eventuals/interrupt.h index bfb0348b..8f4dc584 100644 --- a/eventuals/interrupt.h +++ b/eventuals/interrupt.h @@ -29,6 +29,11 @@ class Interrupt final { CHECK(that.next_ == nullptr); } + Handler& operator=(const Handler&) = delete; + Handler& operator=(Handler&&) noexcept = delete; + + ~Handler() = default; + Interrupt& interrupt() { return *CHECK_NOTNULL(interrupt_); } diff --git a/eventuals/lazy.h b/eventuals/lazy.h index 1f3b1216..f374ff08 100644 --- a/eventuals/lazy.h +++ b/eventuals/lazy.h @@ -18,6 +18,8 @@ struct _Lazy final { using Args = std::enable_if_t>; + _Lazy(const _Lazy&) = delete; + _Lazy(_Lazy&& that) noexcept : args_(std::move(that.args_)) { CHECK(!t_) << "'Lazy' can not be moved after using"; @@ -31,6 +33,11 @@ struct _Lazy final { _Lazy(Args&&... args) : args_(std::forward(args)...) {} + _Lazy& operator=(const _Lazy&) = delete; + _Lazy& operator=(_Lazy&&) noexcept = delete; + + ~_Lazy() = default; + T_* get() { if (!t_) { auto emplace = [this](auto&&... args) mutable { diff --git a/eventuals/lock.h b/eventuals/lock.h index 1820d25c..fcdb7964 100644 --- a/eventuals/lock.h +++ b/eventuals/lock.h @@ -147,12 +147,17 @@ struct _Acquire final { : lock_(lock), k_(std::move(k)) {} + Continuation(const Continuation&) = delete; + Continuation(Continuation&& that) noexcept : lock_(that.lock_), k_(std::move(that.k_)) { CHECK(!waiter_.context) << "moving after starting"; } + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&&) noexcept = delete; + ~Continuation() { CHECK(!waiter_.f) << "continuation still waiting for lock"; } @@ -573,8 +578,12 @@ struct _Wait final { f_(std::move(f)), k_(std::move(k)) {} + Continuation(const Continuation&) = delete; Continuation(Continuation&&) noexcept = default; + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&&) noexcept = delete; + ~Continuation() { CHECK(!waiting_) << "continuation still waiting for lock"; // TODO(benh): CHECK(!waiter_.f) << "continuation still notifiable"; @@ -815,6 +824,18 @@ template class Synchronizable { public: + Synchronizable() = default; + + // Constructors and assignment operators are deleted, because + // 'Lock' class has std::atomic (which is not copyable/moveable), + // and doesn't provide its own copy/move constructors/assignment + // operators. + Synchronizable(const Synchronizable&) = delete; + Synchronizable(Synchronizable&&) noexcept = delete; + + Synchronizable& operator=(const Synchronizable&) = delete; + Synchronizable& operator=(Synchronizable&&) noexcept = delete; + virtual ~Synchronizable() = default; template diff --git a/eventuals/loop.h b/eventuals/loop.h index d11e2639..c05ea4ae 100644 --- a/eventuals/loop.h +++ b/eventuals/loop.h @@ -84,8 +84,11 @@ struct _Loop final { stop_(std::move(stop)), k_(std::move(k)) {} + Continuation(const Continuation&) = delete; Continuation(Continuation&& that) noexcept = default; + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&& that) noexcept { if (this == &that) { return *this; @@ -101,6 +104,8 @@ struct _Loop final { return *this; } + ~Continuation() = default; + void Begin(TypeErasedStream& stream) { stream_ = &stream; diff --git a/eventuals/pipe.h b/eventuals/pipe.h index ac4b262a..667ffbe5 100644 --- a/eventuals/pipe.h +++ b/eventuals/pipe.h @@ -22,6 +22,12 @@ class Pipe final : public Synchronizable { Pipe() : has_values_or_closed_(&lock()) {} + Pipe(const Pipe&) = default; + Pipe(Pipe&&) noexcept = default; + + Pipe& operator=(const Pipe&) = default; + Pipe& operator=(Pipe&&) noexcept = default; + ~Pipe() override = default; [[nodiscard]] auto Write(T&& value) { diff --git a/eventuals/range.h b/eventuals/range.h index 659cbe7a..7f6aab41 100644 --- a/eventuals/range.h +++ b/eventuals/range.h @@ -18,8 +18,12 @@ struct _Range final { step_(step), k_(std::move(k)) {} + Continuation(const Continuation&) = delete; Continuation(Continuation&& that) noexcept = default; + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&&) noexcept = delete; + ~Continuation() override = default; void Start() { diff --git a/eventuals/repeat.h b/eventuals/repeat.h index 92f77c28..0dd79c44 100644 --- a/eventuals/repeat.h +++ b/eventuals/repeat.h @@ -17,8 +17,12 @@ struct _Repeat final { Continuation(K_ k) : k_(std::move(k)) {} + Continuation(const Continuation&) = delete; Continuation(Continuation&& that) noexcept = default; + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&&) noexcept = delete; + ~Continuation() override = default; template diff --git a/eventuals/rsa.h b/eventuals/rsa.h index 5364a92b..84ce1414 100644 --- a/eventuals/rsa.h +++ b/eventuals/rsa.h @@ -53,6 +53,8 @@ class Key final { return *this; } + ~Key() = default; + bool operator==(const Key& that) const { return EVP_PKEY_cmp( CHECK_NOTNULL(key_.get()), @@ -113,6 +115,12 @@ class Key final { template class Key::_Builder final : public builder::Builder { public: + _Builder(const _Builder&) = default; + _Builder(_Builder&&) noexcept = default; + + _Builder& operator=(const _Builder&) = default; + _Builder& operator=(_Builder&&) noexcept = default; + ~_Builder() override = default; auto bits(int bits) && { diff --git a/eventuals/scheduler.cc b/eventuals/scheduler.cc index 017bf692..6d16540c 100644 --- a/eventuals/scheduler.cc +++ b/eventuals/scheduler.cc @@ -12,6 +12,14 @@ namespace eventuals { class DefaultScheduler final : public Scheduler { public: + DefaultScheduler() = default; + + DefaultScheduler(const DefaultScheduler&) = default; + DefaultScheduler(DefaultScheduler&&) noexcept = default; + + DefaultScheduler& operator=(const DefaultScheduler&) = default; + DefaultScheduler& operator=(DefaultScheduler&&) noexcept = default; + ~DefaultScheduler() override = default; bool Continuable(const Context&) override { diff --git a/eventuals/scheduler.h b/eventuals/scheduler.h index e4d700b4..01189971 100644 --- a/eventuals/scheduler.h +++ b/eventuals/scheduler.h @@ -46,17 +46,6 @@ class Scheduler { class Context final : public stout::enable_borrowable_from_this { public: - static stout::borrowed_ref& Get() { - return current_; - } - - static stout::borrowed_ref Switch( - stout::borrowed_ref context) { - stout::borrowed_ref previous = std::move(current_); - current_ = std::move(context); - return previous; - } - Context(Scheduler* scheduler, std::string&& name, void* data = nullptr) : data(data), scheduler_(CHECK_NOTNULL(scheduler)), @@ -67,9 +56,11 @@ class Scheduler { scheduler()->Clone(*this); } - Context(const Context& that) = delete; + Context(const Context&) = delete; + Context(Context&&) noexcept = delete; - Context(Context&& that) = delete; + Context& operator=(const Context&) = delete; + Context& operator=(Context&&) noexcept = delete; ~Context() override { // We shouldn't be using the context we're destructing unless @@ -85,6 +76,17 @@ class Scheduler { WaitUntilBorrowsEquals(0); } + static stout::borrowed_ref& Get() { + return current_; + } + + static stout::borrowed_ref Switch( + stout::borrowed_ref context) { + stout::borrowed_ref previous = std::move(current_); + current_ = std::move(context); + return previous; + } + Scheduler* scheduler() const { return CHECK_NOTNULL(scheduler_); } @@ -150,6 +152,14 @@ class Scheduler { std::string name_; }; + Scheduler() = default; + + Scheduler(const Scheduler&) = default; + Scheduler(Scheduler&&) noexcept = default; + + Scheduler& operator=(const Scheduler&) = default; + Scheduler& operator=(Scheduler&&) noexcept = default; + virtual ~Scheduler() = default; static Scheduler* Default(); @@ -409,6 +419,8 @@ struct _Preempt final { e_(std::move(e)), k_(std::move(k)) {} + Continuation(const Continuation&) = delete; + Continuation(Continuation&& that) noexcept : context_( Scheduler::Default(), @@ -418,6 +430,9 @@ struct _Preempt final { CHECK_EQ(that.previous_, nullptr) << "moving after starting"; } + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&&) noexcept = delete; + ~Continuation() = default; template diff --git a/eventuals/semaphore.h b/eventuals/semaphore.h index 64826894..14e01928 100644 --- a/eventuals/semaphore.h +++ b/eventuals/semaphore.h @@ -53,14 +53,16 @@ class Semaphore { semaphore = CHECK_NOTNULL(CreateSemaphore(nullptr, 0, LONG_MAX, nullptr)); } - Semaphore(const Semaphore& other) = delete; + Semaphore(const Semaphore&) = delete; + Semaphore(Semaphore&&) = delete; + + Semaphore& operator=(const Semaphore&) = delete; + Semaphore& operator=(Semaphore&&) noexcept = delete; ~Semaphore() { CHECK(CloseHandle(semaphore)); } - Semaphore& operator=(const Semaphore& other) = delete; - void Wait() { CHECK_EQ(WAIT_OBJECT_0, WaitForSingleObject(semaphore, INFINITE)); } diff --git a/eventuals/static-thread-pool.h b/eventuals/static-thread-pool.h index 92410024..231c31fd 100644 --- a/eventuals/static-thread-pool.h +++ b/eventuals/static-thread-pool.h @@ -41,6 +41,12 @@ struct Pinned { } Pinned(const Pinned& that) = default; + Pinned(Pinned&&) = default; + + Pinned& operator=(const Pinned&) = default; + Pinned& operator=(Pinned&&) noexcept = default; + + ~Pinned() = default; private: Pinned() = default; @@ -57,7 +63,7 @@ class StaticThreadPool final : public Scheduler { public: struct Requirements final { Requirements(const char* name, Pinned pinned = Pinned::Any()) - : Requirements(std::string(name), std::move(pinned)) {} + : Requirements(std::string(name), pinned) {} Requirements(std::string name, Pinned pinned = Pinned::Any()) : name(std::move(name)), @@ -75,6 +81,12 @@ class StaticThreadPool final : public Scheduler { Schedulable(Pinned pinned) : Schedulable(Requirements("[anonymous]", pinned)) {} + Schedulable(const Schedulable&) = default; + Schedulable(Schedulable&&) noexcept = default; + + Schedulable& operator=(const Schedulable&) = default; + Schedulable& operator=(Schedulable&&) noexcept = default; + virtual ~Schedulable() = default; template @@ -96,6 +108,18 @@ class StaticThreadPool final : public Scheduler { return pool; } + StaticThreadPool(); + + // Can not use default copy/move constructors/assignment + // operators because of std::atomic field. + StaticThreadPool(const StaticThreadPool&) = delete; + StaticThreadPool(StaticThreadPool&&) noexcept = delete; + + StaticThreadPool& operator=(const StaticThreadPool&) = delete; + StaticThreadPool& operator=(StaticThreadPool&&) noexcept = delete; + + ~StaticThreadPool() override; + // Is thread a member of the static pool? static inline thread_local bool member = false; @@ -104,10 +128,6 @@ class StaticThreadPool final : public Scheduler { const unsigned int concurrency; - StaticThreadPool(); - - ~StaticThreadPool() override; - bool Continuable(const Context& context) override; void Submit(Callback callback, Context& context) override; diff --git a/eventuals/stream.h b/eventuals/stream.h index 22ed7ec6..5d94d793 100644 --- a/eventuals/stream.h +++ b/eventuals/stream.h @@ -162,8 +162,11 @@ struct _Stream final { stop_(std::move(stop)), k_(std::move(k)) {} + Continuation(const Continuation&) = delete; Continuation(Continuation&& that) noexcept = default; + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&& that) noexcept { if (this == &that) { return *this; diff --git a/eventuals/take.h b/eventuals/take.h index 695de616..b783cede 100644 --- a/eventuals/take.h +++ b/eventuals/take.h @@ -21,7 +21,11 @@ struct _TakeLast final { : n_(n), k_(std::move(k)) {} - Continuation(Continuation&& that) noexcept = default; + Continuation(const Continuation&) = delete; + Continuation(Continuation&&) noexcept = default; + + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&&) noexcept = delete; ~Continuation() override = default; @@ -148,7 +152,11 @@ struct _TakeRange final { amount_(amount), k_(std::move(k)) {} - Continuation(Continuation&& that) noexcept = default; + Continuation(const Continuation&) = delete; + Continuation(Continuation&&) noexcept = default; + + Continuation& operator=(const Continuation&) = delete; + Continuation& operator=(Continuation&&) noexcept = delete; ~Continuation() override = default; diff --git a/eventuals/task.h b/eventuals/task.h index e26cc870..820853da 100644 --- a/eventuals/task.h +++ b/eventuals/task.h @@ -521,11 +521,16 @@ class _Task final { CHECK(!that.k_.has_value()) << "moving after starting"; } + _Task(const _Task&) = delete; + _Task(_Task&& that) noexcept : e_(std::move(that.e_)) { CHECK(!that.k_.has_value()) << "moving after starting"; } + _Task& operator=(const _Task&) = delete; + _Task& operator=(_Task&&) noexcept = delete; + ~_Task() = default; template diff --git a/eventuals/terminal.h b/eventuals/terminal.h index 5dfcaaa8..cf42482e 100644 --- a/eventuals/terminal.h +++ b/eventuals/terminal.h @@ -175,8 +175,12 @@ struct _Terminal final { struct StoppedException final : public std::exception { StoppedException() = default; - StoppedException(const StoppedException& that) = default; - StoppedException(StoppedException&& that) = default; + + StoppedException(const StoppedException&) = default; + StoppedException(StoppedException&&) = default; + + StoppedException& operator=(const StoppedException&) = delete; + StoppedException& operator=(StoppedException&&) noexcept = delete; ~StoppedException() override = default; diff --git a/eventuals/type-erased-stream.h b/eventuals/type-erased-stream.h index 786994e1..f5e4e819 100644 --- a/eventuals/type-erased-stream.h +++ b/eventuals/type-erased-stream.h @@ -7,7 +7,16 @@ namespace eventuals { //////////////////////////////////////////////////////////////////////// struct TypeErasedStream { + TypeErasedStream() = default; + + TypeErasedStream(const TypeErasedStream&) = default; + TypeErasedStream(TypeErasedStream&&) noexcept = default; + + TypeErasedStream& operator=(const TypeErasedStream&) = default; + TypeErasedStream& operator=(TypeErasedStream&&) noexcept = default; + virtual ~TypeErasedStream() = default; + virtual void Next() = 0; virtual void Done() = 0; }; diff --git a/eventuals/x509.h b/eventuals/x509.h index 09baa708..7fa04b43 100644 --- a/eventuals/x509.h +++ b/eventuals/x509.h @@ -57,6 +57,8 @@ class Certificate final { return *this; } + ~Certificate() = default; + operator X509*() { return CHECK_NOTNULL(certificate_.get()); } @@ -96,6 +98,12 @@ template < bool has_organization_name_> class Certificate::_Builder final : public builder::Builder { public: + _Builder(const _Builder&) = default; + _Builder(_Builder&&) noexcept = default; + + _Builder& operator=(const _Builder&) = default; + _Builder& operator=(_Builder&&) noexcept = default; + ~_Builder() override = default; auto subject_key(rsa::Key&& subject_key) && {