File tree Expand file tree Collapse file tree 2 files changed +10
-9
lines changed Expand file tree Collapse file tree 2 files changed +10
-9
lines changed Original file line number Diff line number Diff line change @@ -144,8 +144,10 @@ namespace mamba
144
144
private:
145
145
146
146
std::atomic<bool > is_open{ true };
147
- util::synchronized_value<std::vector<std::thread>> threads;
148
- util::synchronized_value<std::vector<on_close_handler>> close_handlers;
147
+ using Threads = std::vector<std::thread>;
148
+ using CloseHandlers = std::vector<on_close_handler>;
149
+ util::synchronized_value<Threads, std::recursive_mutex> threads;
150
+ util::synchronized_value<CloseHandlers, std::recursive_mutex> close_handlers;
149
151
150
152
void invoke_close_handlers ();
151
153
};
Original file line number Diff line number Diff line change 9
9
#include < mutex>
10
10
11
11
#include " mamba/util/build.hpp"
12
+ #include " mamba/util/synchronized_value.hpp"
12
13
13
14
extern " C"
14
15
{
@@ -105,19 +106,18 @@ namespace mamba
105
106
106
107
static std::atomic<MainExecutor*> main_executor{ nullptr };
107
108
108
- static std::unique_ptr<MainExecutor> default_executor;
109
- static std::mutex default_executor_mutex; // TODO: replace by synchronized_value once available
109
+ static util::synchronized_value<std::unique_ptr<MainExecutor>> default_executor;
110
110
111
111
MainExecutor& MainExecutor::instance ()
112
112
{
113
113
if (!main_executor)
114
114
{
115
115
// When no MainExecutor was created before we create a static one.
116
- std::scoped_lock lock{ default_executor_mutex } ;
116
+ auto synched_default_executor = default_executor. synchronize () ;
117
117
if (!main_executor) // double check necessary to avoid data race
118
118
{
119
- default_executor = std::make_unique<MainExecutor>();
120
- assert (main_executor == default_executor. get ());
119
+ *synched_default_executor = std::make_unique<MainExecutor>();
120
+ assert (main_executor == synched_default_executor-> get ());
121
121
}
122
122
}
123
123
@@ -126,8 +126,7 @@ namespace mamba
126
126
127
127
void MainExecutor::stop_default ()
128
128
{
129
- std::scoped_lock lock{ default_executor_mutex };
130
- default_executor.reset ();
129
+ default_executor->reset ();
131
130
}
132
131
133
132
MainExecutor::MainExecutor ()
You can’t perform that action at this time.
0 commit comments