Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions console/executor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ using namespace system;
using namespace std::placeholders;

// static initializers.
std::thread executor::stop_poller_{};
std::promise<bool> executor::stopping_{};
std::atomic<bool> executor::initialized_{};
std::atomic<int> executor::signal_{ unsignalled };
std::unique_ptr<std::thread> executor::stop_poller_{};

executor::executor(parser& metadata, std::istream& input, std::ostream& output,
std::ostream&)
Expand All @@ -59,9 +59,6 @@ executor::executor(parser& metadata, std::istream& input, std::ostream& output,
metadata.configured.log.verbose
}
{
BC_ASSERT(!initialized_);
initialized_ = true;

initialize_stop();

#if defined(HAVE_MSC)
Expand All @@ -71,11 +68,11 @@ executor::executor(parser& metadata, std::istream& input, std::ostream& output,

executor::~executor()
{
initialized_ = false;

#if defined(HAVE_MSC)
destroy_hidden_window();
#endif

uninitialize_stop();
}

// Stop signal.
Expand Down Expand Up @@ -112,6 +109,9 @@ BOOL WINAPI executor::control_handler(DWORD signal)

void executor::initialize_stop()
{
BC_ASSERT(!initialized_);
initialized_ = true;

poll_for_stopping();

#if defined(HAVE_MSC)
Expand Down Expand Up @@ -146,6 +146,19 @@ void executor::initialize_stop()
#endif
}

void executor::uninitialize_stop()
{
BC_ASSERT(initialized_);
initialized_ = false;

stop();
if (stop_poller_ && stop_poller_->joinable())
{
stop_poller_->join();
stop_poller_.reset();
}
}

// Handle the stop signal and invoke stop method (requries signal safe code).
void executor::handle_stop(int signal)
{
Expand Down Expand Up @@ -179,12 +192,10 @@ bool executor::canceled()
// Spinning must be used in signal handler, cannot wait on a promise.
void executor::poll_for_stopping()
{
using namespace std::this_thread;

stop_poller_ = std::thread([]()
stop_poller_ = std::make_unique<std::thread>([]()
{
while (!canceled())
sleep_for(std::chrono::milliseconds(10));
std::this_thread::sleep_for(std::chrono::milliseconds(10));

stopping_.set_value(true);
});
Expand All @@ -194,8 +205,6 @@ void executor::poll_for_stopping()
void executor::wait_for_stopping()
{
stopping_.get_future().wait();
if (stop_poller_.joinable())
stop_poller_.join();
}

// Suspend verbose logging and log the stop signal.
Expand Down
3 changes: 2 additions & 1 deletion console/executor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class executor

// Executor (static).
static void initialize_stop();
static void uninitialize_stop();
static void poll_for_stopping();
static void wait_for_stopping();
static void handle_stop(int code);
Expand Down Expand Up @@ -171,10 +172,10 @@ class executor
static const std::unordered_map<uint8_t, std::string> fired_;

// Shutdown.
static std::thread stop_poller_;
static std::atomic<int> signal_;
static std::atomic<bool> initialized_;
static std::promise<bool> stopping_;
static std::unique_ptr<std::thread> stop_poller_;
std::promise<bool> log_suspended_{};

parser& metadata_;
Expand Down
10 changes: 10 additions & 0 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1027,6 +1027,16 @@ options_metadata parser::load_settings() THROWS
value<std::string>(&configured.server.bitcoind.key_pass),
"The password to decrypt the server private key file (.PEM), optional."
)
(
"bitcoind.username",
value<std::string>(&configured.server.bitcoind.username),
"The http basic authorization username (not secure)."
)
(
"bitcoind.password",
value<std::string>(&configured.server.bitcoind.password),
"The http basic authorization password (not secure)."
)
(
"bitcoind.connections",
value<uint16_t>(&configured.server.bitcoind.connections),
Expand Down
Loading