4
4
5
5
namespace bb ::crypto::merkle_tree {
6
6
/* *
7
- * @brief Used in parallel insertions in the the IndexedTree. Workers signal to other following workes as they move up
7
+ * @brief Used in parallel insertions in the IndexedTree. Workers signal to other following workes as they move up
8
8
* the level of the tree.
9
9
*
10
10
*/
11
11
class Signal {
12
12
public:
13
- Signal (uint32_t initial_level = 1 )
14
- : signal_(initial_level){};
13
+ explicit Signal (uint32_t initial_level = 1 )
14
+ : signal_(std::make_unique<std::atomic< uint32_t >>( initial_level) ){};
15
15
~Signal () = default ;
16
16
Signal (const Signal& other)
17
- : signal_(other.signal_. load())
17
+ : signal_(std::make_unique<std::atomic< uint32_t >>( other.signal_-> load () ))
18
18
{}
19
- Signal (const Signal&& other) = delete ;
19
+ Signal (Signal&& other) = default ;
20
20
Signal& operator =(const Signal& other)
21
21
{
22
22
if (this != &other) {
23
- signal_. store (other.signal_ . load ());
23
+ signal_-> store (other.signal_ -> load ());
24
24
}
25
25
return *this ;
26
26
}
27
- Signal& operator =(const Signal&& other) = delete ;
27
+ Signal& operator =(Signal&& other) = default ;
28
28
29
29
/* *
30
30
* @brief Causes the thread to wait until the required level has been signalled
@@ -33,10 +33,10 @@ class Signal {
33
33
*/
34
34
void wait_for_level (uint32_t level = 0 )
35
35
{
36
- uint32_t current_level = signal_. load ();
36
+ uint32_t current_level = signal_-> load ();
37
37
while (current_level > level) {
38
- signal_. wait (current_level);
39
- current_level = signal_. load ();
38
+ signal_-> wait (current_level);
39
+ current_level = signal_-> load ();
40
40
}
41
41
}
42
42
@@ -47,17 +47,18 @@ class Signal {
47
47
*/
48
48
void signal_level (uint32_t level = 0 )
49
49
{
50
- signal_. store (level);
51
- signal_. notify_all ();
50
+ signal_-> store (level);
51
+ signal_-> notify_all ();
52
52
}
53
53
54
54
void signal_decrement (uint32_t delta = 1 )
55
55
{
56
- signal_. fetch_sub (delta);
57
- signal_. notify_all ();
56
+ signal_-> fetch_sub (delta);
57
+ signal_-> notify_all ();
58
58
}
59
59
60
60
private:
61
- std::atomic<uint32_t > signal_;
61
+ // apple clang has issues if this cannot be move-constructed, so we wrap in unique_ptr
62
+ std::unique_ptr<std::atomic<uint32_t >> signal_;
62
63
};
63
64
} // namespace bb::crypto::merkle_tree
0 commit comments