Skip to content

Commit

Permalink
chore: patch net.xx files (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
naqvis authored Jan 13, 2025
1 parent a2c4bb3 commit ddd5f55
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
8 changes: 6 additions & 2 deletions src/net.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,14 @@
namespace pipy {

Net* Net::s_main = nullptr;
thread_local Net Net::s_current;

auto Net::current() -> Net& {
static thread_local Net s_current;
return s_current;
}

void Net::init() {
s_main = &s_current;
s_main = &current();

#ifdef _WIN32
asio::detail::win_thread::set_terminate_threads(true);
Expand Down
9 changes: 3 additions & 6 deletions src/net.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,13 @@ class Net {
return *s_main;
}

static auto current() -> Net& {
return s_current;
}
static auto current() -> Net&;

static auto context() -> asio::io_context& {
return s_current.m_io_context;
return current().m_io_context;
}

static bool is_main() { return &s_current == s_main; }
static bool is_main() { return &current() == s_main; }

auto io_context() -> asio::io_context& { return m_io_context; }
bool is_running() const { return m_is_running; }
Expand All @@ -72,7 +70,6 @@ class Net {
asio::io_context m_io_context;
bool m_is_running;
static Net* s_main;
static thread_local Net s_current;
};

//
Expand Down

0 comments on commit ddd5f55

Please sign in to comment.