Skip to content

Remove unnecessarily public + repeated singleton initialisation #7123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 17, 2025
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
8 changes: 0 additions & 8 deletions src/consensus/aft/test/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,6 @@

using namespace std;

std::unique_ptr<threading::ThreadMessaging>
threading::ThreadMessaging::singleton = nullptr;

namespace threading
{
std::map<std::thread::id, uint16_t> thread_ids;
}

constexpr auto shash = ccf::ds::fnv_1a<size_t>;

int main(int argc, char** argv)
Expand Down
3 changes: 0 additions & 3 deletions src/consensus/aft/test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
#define DOCTEST_CONFIG_IMPLEMENT
#include <doctest/doctest.h>

std::unique_ptr<threading::ThreadMessaging>
threading::ThreadMessaging::singleton = nullptr;

using ms = std::chrono::milliseconds;

DOCTEST_TEST_CASE("Single node startup" * doctest::test_suite("single"))
Expand Down
10 changes: 8 additions & 2 deletions src/ds/thread_messaging.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,11 @@ namespace threading
return tasks[task_id];
}

static std::unique_ptr<ThreadMessaging> singleton;
static std::unique_ptr<ThreadMessaging>& get_singleton()
{
static std::unique_ptr<ThreadMessaging> singleton = nullptr;
return singleton;
}

public:
static constexpr uint16_t max_num_threads = 24;
Expand All @@ -262,6 +266,7 @@ namespace threading

static void init(uint16_t num_task_queues)
{
auto& singleton = get_singleton();
if (singleton != nullptr)
{
throw std::logic_error("Called init() multiple times");
Expand All @@ -272,11 +277,12 @@ namespace threading

static void shutdown()
{
singleton.reset();
get_singleton().reset();
}

static ThreadMessaging& instance()
{
auto& singleton = get_singleton();
if (singleton == nullptr)
{
throw std::logic_error(
Expand Down
3 changes: 0 additions & 3 deletions src/enclave/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ static std::atomic<ccf::Enclave*> e;
std::atomic<uint16_t> num_pending_threads = 0;
std::atomic<uint16_t> num_complete_threads = 0;

std::unique_ptr<threading::ThreadMessaging>
threading::ThreadMessaging::singleton = nullptr;

constexpr size_t min_gap_between_initiation_attempts_us =
2'000'000; // 2 seconds
std::chrono::microseconds ccf::Channel::min_gap_between_initiation_attempts(
Expand Down
5 changes: 0 additions & 5 deletions src/indexing/test/indexing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,6 @@
#define DOCTEST_CONFIG_IMPLEMENT
#include <doctest/doctest.h>

// Transitively see a header that tries to use ThreadMessaging, so need to
// create static singleton
std::unique_ptr<threading::ThreadMessaging>
threading::ThreadMessaging::singleton = nullptr;

using IndexA = ccf::indexing::strategies::SeqnosByKey_InMemory<decltype(map_a)>;
using LazyIndexA = ccf::indexing::LazyStrategy<IndexA>;

Expand Down
6 changes: 0 additions & 6 deletions src/node/rpc/test/frontend_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,6 @@
#include <iostream>
#include <string>

namespace threading
{
std::unique_ptr<::threading::ThreadMessaging> ThreadMessaging::singleton =
nullptr;
};

using namespace ccf;
using namespace std;

Expand Down
3 changes: 0 additions & 3 deletions src/node/test/channels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,6 @@ void sleep_to_reinitiate()
2 * ccf::Channel::min_gap_between_initiation_attempts);
}

std::unique_ptr<threading::ThreadMessaging>
threading::ThreadMessaging::singleton = nullptr;

class IORingbuffersFixture
{
protected:
Expand Down
3 changes: 0 additions & 3 deletions src/node/test/historical_queries.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
#define DOCTEST_CONFIG_IMPLEMENT
#include <doctest/doctest.h>

std::unique_ptr<threading::ThreadMessaging>
threading::ThreadMessaging::singleton = nullptr;

using NumToString = ccf::kv::Map<size_t, std::string>;

constexpr size_t certificate_validity_period_days = 365;
Expand Down
3 changes: 0 additions & 3 deletions src/node/test/history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@
#include <doctest/doctest.h>
#undef FAIL

std::unique_ptr<threading::ThreadMessaging>
threading::ThreadMessaging::singleton = nullptr;

using MapT = ccf::kv::Map<size_t, size_t>;

constexpr size_t certificate_validity_period_days = 365;
Expand Down
8 changes: 0 additions & 8 deletions src/node/test/history_bench.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@
#define PICOBENCH_IMPLEMENT
#include <picobench/picobench.hpp>

std::unique_ptr<threading::ThreadMessaging>
threading::ThreadMessaging::singleton = nullptr;

namespace threading
{
std::map<std::thread::id, uint16_t> thread_ids;
}

using namespace ccf;

class DummyConsensus : public ccf::kv::test::StubConsensus
Expand Down
3 changes: 0 additions & 3 deletions src/node/test/snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,6 @@
#undef FAIL
#include <string>

std::unique_ptr<threading::ThreadMessaging>
threading::ThreadMessaging::singleton = nullptr;

TEST_CASE("Snapshot with merkle tree" * doctest::test_suite("snapshot"))
{
auto source_consensus = std::make_shared<ccf::kv::test::StubConsensus>();
Expand Down
5 changes: 0 additions & 5 deletions src/node/test/snapshotter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,6 @@
#include <doctest/doctest.h>
#include <string>

// Because snapshot serialisation is costly, the snapshotter serialises
// snapshots asynchronously.
std::unique_ptr<threading::ThreadMessaging>
threading::ThreadMessaging::singleton = nullptr;

constexpr auto buffer_size = 1024 * 16;
auto node_kp = ccf::crypto::make_key_pair();

Expand Down