|
11 | 11 | #include <string>
|
12 | 12 | #include <thread>
|
13 | 13 | #include <unordered_map>
|
| 14 | +#include <unordered_set> |
14 | 15 |
|
15 | 16 | #include "caf/abstract_actor.hpp"
|
16 | 17 | #include "caf/actor.hpp"
|
@@ -53,19 +54,32 @@ class CAF_CORE_EXPORT actor_registry {
|
53 | 54 |
|
54 | 55 | /// Increases running-actors-count by one.
|
55 | 56 | /// @returns the increased count.
|
56 |
| - size_t inc_running(); |
| 57 | + size_t inc_running(actor_id key); |
57 | 58 |
|
58 | 59 | /// Decreases running-actors-count by one.
|
59 | 60 | /// @returns the decreased count.
|
60 |
| - size_t dec_running(); |
| 61 | + size_t dec_running(actor_id key); |
61 | 62 |
|
62 | 63 | /// Returns the number of currently running actors.
|
63 | 64 | size_t running() const;
|
64 | 65 |
|
65 |
| - /// Blocks the caller until running-actors-count becomes `expected` |
66 |
| - /// (must be either 0 or 1). |
| 66 | + /// Returns the the actor ids of all currently running actors. |
| 67 | + const std::unordered_set<actor_id>& running_ids() const; |
| 68 | + |
| 69 | + /// Blocks the caller until running-actors-count becomes `expected`.. |
67 | 70 | void await_running_count_equal(size_t expected) const;
|
68 | 71 |
|
| 72 | + /// Blocks the caller until running-actors-count becomes `expected`.. |
| 73 | + /// Invokes `cb` every time the set of running actors shrinks. |
| 74 | + template <class CB> |
| 75 | + void await_running_count_equal(size_t expected, CB&& cb) const { |
| 76 | + std::unique_lock<std::mutex> guard{running_mtx_}; |
| 77 | + while (running_.size() != expected) { |
| 78 | + running_cv_.wait(guard); |
| 79 | + cb(); |
| 80 | + } |
| 81 | + } |
| 82 | + |
69 | 83 | /// Returns the actor associated with `key` or `invalid_actor`.
|
70 | 84 | template <class T = strong_actor_ptr>
|
71 | 85 | T get(const std::string& key) const {
|
@@ -112,6 +126,7 @@ class CAF_CORE_EXPORT actor_registry {
|
112 | 126 |
|
113 | 127 | mutable std::mutex running_mtx_;
|
114 | 128 | mutable std::condition_variable running_cv_;
|
| 129 | + std::unordered_set<actor_id> running_; |
115 | 130 |
|
116 | 131 | mutable detail::shared_spinlock instances_mtx_;
|
117 | 132 | entries entries_;
|
|
0 commit comments