Skip to content

Commit ddd5f55

Browse files
authored
chore: patch net.xx files (#205)
1 parent a2c4bb3 commit ddd5f55

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/net.cpp

+6-2
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,14 @@
2828
namespace pipy {
2929

3030
Net* Net::s_main = nullptr;
31-
thread_local Net Net::s_current;
31+
32+
auto Net::current() -> Net& {
33+
static thread_local Net s_current;
34+
return s_current;
35+
}
3236

3337
void Net::init() {
34-
s_main = &s_current;
38+
s_main = &current();
3539

3640
#ifdef _WIN32
3741
asio::detail::win_thread::set_terminate_threads(true);

src/net.hpp

+3-6
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,13 @@ class Net {
4848
return *s_main;
4949
}
5050

51-
static auto current() -> Net& {
52-
return s_current;
53-
}
51+
static auto current() -> Net&;
5452

5553
static auto context() -> asio::io_context& {
56-
return s_current.m_io_context;
54+
return current().m_io_context;
5755
}
5856

59-
static bool is_main() { return &s_current == s_main; }
57+
static bool is_main() { return &current() == s_main; }
6058

6159
auto io_context() -> asio::io_context& { return m_io_context; }
6260
bool is_running() const { return m_is_running; }
@@ -72,7 +70,6 @@ class Net {
7270
asio::io_context m_io_context;
7371
bool m_is_running;
7472
static Net* s_main;
75-
static thread_local Net s_current;
7673
};
7774

7875
//

0 commit comments

Comments
 (0)