Skip to content

Commit 2d92b10

Browse files
committed
feat: delete copy and move
1 parent 3b7df67 commit 2d92b10

File tree

9 files changed

+55
-10
lines changed

9 files changed

+55
-10
lines changed

include/coro/channel.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ struct channel {
1919
close();
2020
}
2121

22+
channel(const channel&) = delete;
23+
channel(channel&&) = delete;
24+
channel& operator=(const channel&) = delete;
25+
channel& operator=(channel&&) = delete;
26+
2227
struct send_awaitable {
2328
channel* ch_;
2429
T value_;

include/coro/condition_variable.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ struct condition_variable_t {
3030
public:
3131
condition_variable_t() : head_(nullptr), tail_(nullptr) {}
3232

33+
condition_variable_t(const condition_variable_t&) = delete;
34+
condition_variable_t(condition_variable_t&&) = delete;
35+
condition_variable_t& operator=(const condition_variable_t&) = delete;
36+
condition_variable_t& operator=(condition_variable_t&&) = delete;
37+
3338
// Wait releases the mutex and suspends the coroutine
3439
// When resumed by notify, the mutex is NOT automatically re-acquired
3540
// You must manually re-acquire the lock after wait returns

include/coro/event.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ struct event_t {
2828
wg_.add(1); // Start with counter = 1 (unset state)
2929
}
3030

31+
event_t(const event_t&) = delete;
32+
event_t(event_t&&) = delete;
33+
event_t& operator=(const event_t&) = delete;
34+
event_t& operator=(event_t&&) = delete;
35+
3136
// Set the event and wake up all waiting coroutines
3237
// All current and future waiters will proceed until clear() is called
3338
// Usage: evt.set();
Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#include "executor.hpp"
1313

1414
namespace coro {
15-
class executor_basic_task : public coro::executor {
15+
class executor_base : public coro::executor {
1616
protected:
1717
struct DelayedTask {
1818
std::chrono::steady_clock::time_point execute_at;
@@ -61,12 +61,17 @@ class executor_basic_task : public coro::executor {
6161
}
6262

6363
public:
64-
executor_basic_task() = default;
64+
executor_base() = default;
6565

66-
~executor_basic_task() override {
67-
executor_basic_task::stop();
66+
~executor_base() override {
67+
executor_base::stop();
6868
}
6969

70+
executor_base(const executor_base&) = delete;
71+
executor_base(executor_base&&) = delete;
72+
executor_base& operator=(const executor_base&) = delete;
73+
executor_base& operator=(executor_base&&) = delete;
74+
7075
void dispatch(std::function<void()> fn) override {
7176
if (running_thread_id_.load(std::memory_order_acquire) == std::hash<std::thread::id>{}(std::this_thread::get_id())) {
7277
fn();

include/coro/executor_loop.hpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "executor_poll.hpp"
1414

1515
namespace coro {
16-
class executor_loop : public executor_basic_task {
16+
class executor_loop : public executor_base {
1717
private:
1818
std::condition_variable condition_;
1919

@@ -23,6 +23,11 @@ class executor_loop : public executor_basic_task {
2323
executor_loop::stop();
2424
};
2525

26+
executor_loop(const executor_loop&) = delete;
27+
executor_loop(executor_loop&&) = delete;
28+
executor_loop& operator=(const executor_loop&) = delete;
29+
executor_loop& operator=(executor_loop&&) = delete;
30+
2631
void run_loop() {
2732
running_thread_id_.store(std::hash<std::thread::id>{}(std::this_thread::get_id()), std::memory_order_release);
2833
for (;;) {
@@ -76,17 +81,17 @@ class executor_loop : public executor_basic_task {
7681
}
7782

7883
void post_delayed_ns(std::function<void()> fn, const uint64_t delay_ns) override {
79-
executor_basic_task::post_delayed_ns(std::move(fn), delay_ns);
84+
executor_base::post_delayed_ns(std::move(fn), delay_ns);
8085
condition_.notify_one();
8186
}
8287

8388
void post(std::function<void()> fn) override {
84-
executor_basic_task::post(std::move(fn));
89+
executor_base::post(std::move(fn));
8590
condition_.notify_one();
8691
}
8792

8893
void stop() override {
89-
executor_basic_task::stop();
94+
executor_base::stop();
9095
condition_.notify_one();
9196
}
9297
};

include/coro/executor_poll.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
#pragma once
22

3-
#include "executor_basic_task.hpp"
3+
#include "executor_base.hpp"
44

55
namespace coro {
66

7-
class executor_poll : public executor_basic_task {
7+
class executor_poll : public executor_base {
88
public:
99
executor_poll() = default;
1010
~executor_poll() override = default;
1111

12+
executor_poll(const executor_poll&) = delete;
13+
executor_poll(executor_poll&&) = delete;
14+
executor_poll& operator=(const executor_poll&) = delete;
15+
executor_poll& operator=(executor_poll&&) = delete;
16+
1217
void poll() {
1318
if (!running_thread_id_.load(std::memory_order_acquire)) {
1419
running_thread_id_.store(std::hash<std::thread::id>{}(std::this_thread::get_id()), std::memory_order_release);

include/coro/latch.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,11 @@ struct latch_t {
3030
}
3131
}
3232

33+
latch_t(const latch_t&) = delete;
34+
latch_t(latch_t&&) = delete;
35+
latch_t& operator=(const latch_t&) = delete;
36+
latch_t& operator=(latch_t&&) = delete;
37+
3338
// Count down the latch by n (default 1)
3439
// When the count reaches zero, all waiting coroutines are resumed
3540
void count_down(int n = 1) {

include/coro/semaphore.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@ struct counting_semaphore_t {
3131
explicit counting_semaphore_t(int desired, int least_max_value = INT_MAX)
3232
: counter_(desired), max_value_(least_max_value), head_(nullptr), tail_(nullptr) {}
3333

34+
counting_semaphore_t(const counting_semaphore_t&) = delete;
35+
counting_semaphore_t(counting_semaphore_t&&) = delete;
36+
counting_semaphore_t& operator=(const counting_semaphore_t&) = delete;
37+
counting_semaphore_t& operator=(counting_semaphore_t&&) = delete;
38+
3439
// Acquire n permits (default 1)
3540
// Suspends if not enough permits are available
3641
struct acquire_awaitable {

include/coro/wait_group.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ struct wait_group_t {
2828
public:
2929
wait_group_t() : counter_(0), head_(nullptr), tail_(nullptr) {}
3030

31+
wait_group_t(const wait_group_t&) = delete;
32+
wait_group_t(wait_group_t&&) = delete;
33+
wait_group_t& operator=(const wait_group_t&) = delete;
34+
wait_group_t& operator=(wait_group_t&&) = delete;
35+
3136
// Add delta to the wait group counter
3237
// Similar to Go's wg.Add(delta)
3338
void add(int delta) {

0 commit comments

Comments
 (0)