Skip to content

Commit 7c69021

Browse files
committed
Minor fixes
1 parent 3f547c1 commit 7c69021

10 files changed

Lines changed: 35 additions & 93 deletions

File tree

modules/Container/NetworkPtr.mpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,29 +52,29 @@ export namespace CppUtils::Container
5252
return ptr;
5353
}
5454

55-
[[nodiscard]] inline auto isRoot() const -> bool
55+
[[nodiscard]] inline auto isRoot() const noexcept -> bool
5656
{
5757
return m_isRoot;
5858
}
5959

60-
[[nodiscard]] inline auto isTemporary() const -> bool
60+
[[nodiscard]] inline auto isTemporary() const noexcept -> bool
6161
{
6262
return not m_isRoot and std::empty(m_parents);
6363
}
6464

65-
inline auto setRoot(bool isRoot) -> void
65+
inline auto setRoot(bool isRoot) noexcept -> void
6666
{
6767
m_isRoot = isRoot;
6868
if (m_isRoot)
6969
m_distanceFromRoot = 0;
7070
}
7171

72-
inline auto setWeakThis(WeakPtr ptr) -> void
72+
inline auto setWeakThis(WeakPtr ptr) noexcept -> void
7373
{
7474
m_weak_this = std::move(ptr);
7575
}
7676

77-
[[nodiscard]] inline auto getDistanceFromRoot() const -> std::size_t
77+
[[nodiscard]] inline auto getDistanceFromRoot() const noexcept -> std::size_t
7878
{
7979
return m_distanceFromRoot;
8080
}

modules/Execution/Planner.mpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,14 @@ export namespace CppUtils::Execution
1414
m_conditionVariable.notify_all();
1515
}
1616

17-
inline auto schedule(auto&& function, CppUtils::Chrono::Duration auto delay) -> void
17+
inline auto schedule(auto&& function, const CppUtils::Chrono::Duration auto& delay) -> void
1818
{
1919
if (not m_active)
2020
return;
2121

22+
auto lockGuard = std::unique_lock{m_mutex};
2223
m_threads.emplace_back(std::jthread{[this, function = std::forward<decltype(function)>(function), delay]() mutable -> void {
23-
auto lockGuard = std::unique_lock{m_mutex};
24+
auto lockGuard = std::unique_lock{m_conditionVariableMutex};
2425
if (m_conditionVariable.wait_for(lockGuard, delay, [this] { return not m_active.load(); }))
2526
return;
2627
if (m_active)
@@ -29,9 +30,10 @@ export namespace CppUtils::Execution
2930
}
3031

3132
private:
32-
std::atomic<bool> m_active = true;
33-
std::vector<std::jthread> m_threads;
3433
std::mutex m_mutex;
34+
std::atomic_bool m_active = true;
35+
std::vector<std::jthread> m_threads;
36+
std::mutex m_conditionVariableMutex;
3537
std::condition_variable m_conditionVariable;
3638
};
3739
}

modules/Thread/StreamListener.mpp

Lines changed: 0 additions & 59 deletions
This file was deleted.

modules/Thread/ThreadLoop.mpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@ export namespace CppUtils::Thread
4343
try
4444
{
4545
while (not stopToken.stop_requested())
46-
data->function();
46+
if (data->function)
47+
data->function();
4748
return;
4849
}
4950
catch (const std::exception& exception)

tests/Execution/EventSystem.mpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ export namespace CppUtils::UnitTest::Execution::EventSystem
4444

4545
suite.addTest("Send/Receive", [&] {
4646
auto eventSystem = CppUtils::Execution::EventSystem{};
47-
auto expectPingReceived = std::atomic<bool>{false};
47+
auto expectPingReceived = std::atomic_bool{false};
4848

4949
eventSystem.subscribe<>([&expectPingReceived, &suite](const std::string& message) -> void {
5050
Logger::print("{}\n", message);
@@ -58,7 +58,7 @@ export namespace CppUtils::UnitTest::Execution::EventSystem
5858

5959
suite.addTest("Send/Receive with name", [&] {
6060
auto eventSystem = CppUtils::Execution::EventSystem{};
61-
auto expectPingReceived = std::atomic<bool>{false};
61+
auto expectPingReceived = std::atomic_bool{false};
6262

6363
eventSystem.subscribe<"Ping">([&expectPingReceived, &suite](const std::string& message) -> void {
6464
Logger::print("{}\n", message);
@@ -76,8 +76,8 @@ export namespace CppUtils::UnitTest::Execution::EventSystem
7676

7777
suite.addTest("Cascade calls", [&] {
7878
auto eventSystem = CppUtils::Execution::EventSystem{};
79-
auto expectPingReceived = std::atomic<bool>{false};
80-
auto expectPongReceived = std::atomic<bool>{false};
79+
auto expectPingReceived = std::atomic_bool{false};
80+
auto expectPongReceived = std::atomic_bool{false};
8181

8282
eventSystem.subscribe<"Ping">([&expectPingReceived, &suite, &eventSystem](const std::string& message) -> void {
8383
Logger::print("{}\n", message);
@@ -98,8 +98,8 @@ export namespace CppUtils::UnitTest::Execution::EventSystem
9898

9999
suite.addTest("Multiple subscribers", [&] {
100100
auto eventSystem = CppUtils::Execution::EventSystem{};
101-
auto expect1 = std::atomic<bool>{false};
102-
auto expect2 = std::atomic<bool>{false};
101+
auto expect1 = std::atomic_bool{false};
102+
auto expect2 = std::atomic_bool{false};
103103

104104
eventSystem.subscribe<"Event">([&expect1](std::nullptr_t) -> void {
105105
expect1 = true;

tests/Execution/Planner.mpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export namespace CppUtils::UnitTest::Execution::Planner
1111

1212
suite.addTest("Schedule and execute", [&] {
1313
auto planner = CppUtils::Execution::Planner{};
14-
auto executed = std::atomic<bool>{false};
14+
auto executed = std::atomic_bool{false};
1515

1616
planner.schedule([&executed] {
1717
executed = true;
@@ -23,7 +23,7 @@ export namespace CppUtils::UnitTest::Execution::Planner
2323
});
2424

2525
suite.addTest("Cancel tasks on destruction", [&] {
26-
auto executed = std::atomic<bool>{false};
26+
auto executed = std::atomic_bool{false};
2727

2828
{
2929
auto planner = CppUtils::Execution::Planner{};
@@ -40,7 +40,7 @@ export namespace CppUtils::UnitTest::Execution::Planner
4040

4141
suite.addTest("Multiple tasks", [&] {
4242
auto planner = CppUtils::Execution::Planner{};
43-
auto counter = std::atomic<std::size_t>{0};
43+
auto counter = std::atomic_size_t{0};
4444

4545
planner.schedule([&counter] { ++counter; }, 10ms);
4646
planner.schedule([&counter] { ++counter; }, 20ms);

tests/FileSystem/Watcher.mpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ export namespace CppUtils::UnitTest::FileSystem::Watcher
5353

5454
suite.addTest("Watch file creation", [&] {
5555
CppUtils::FileSystem::TemporaryDirectory{[&suite](const auto& directory) -> void {
56-
auto expectCreateFile = std::atomic<bool>{false};
57-
auto expectCloseFile = std::atomic<bool>{false};
56+
auto expectCreateFile = std::atomic_bool{false};
57+
auto expectCloseFile = std::atomic_bool{false};
5858
auto filePath = directory / "test.tmp";
5959

6060
auto watcher = CppUtils::FileSystem::Watcher{};
@@ -90,7 +90,7 @@ export namespace CppUtils::UnitTest::FileSystem::Watcher
9090

9191
suite.addTest("Watch file modification", [&] {
9292
CppUtils::FileSystem::TemporaryDirectory{[&suite](const auto& directory) -> void {
93-
auto expectModifyFile = std::atomic<bool>{false};
93+
auto expectModifyFile = std::atomic_bool{false};
9494
auto filePath = directory / "test.tmp";
9595
CppUtils::FileSystem::String::write(filePath, "Foo");
9696

@@ -118,7 +118,7 @@ export namespace CppUtils::UnitTest::FileSystem::Watcher
118118

119119
suite.addTest("Watch file modification in a directory", [&] {
120120
CppUtils::FileSystem::TemporaryDirectory{[&suite](const auto& directory) -> void {
121-
auto expectModifyFile = std::atomic<bool>{false};
121+
auto expectModifyFile = std::atomic_bool{false};
122122
auto filePath = directory / "test.tmp";
123123
CppUtils::FileSystem::String::write(filePath, "Foo");
124124

@@ -146,7 +146,7 @@ export namespace CppUtils::UnitTest::FileSystem::Watcher
146146

147147
suite.addTest("Watch file deletion", [&] {
148148
CppUtils::FileSystem::TemporaryDirectory{[&suite](const auto& directory) -> void {
149-
auto expectDeleteFile = std::atomic<bool>{false};
149+
auto expectDeleteFile = std::atomic_bool{false};
150150
auto filePath = directory / "test.tmp";
151151
CppUtils::FileSystem::String::write(filePath, "Hello World!");
152152

tests/Thread/ThreadPool.mpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export namespace CppUtils::UnitTest::Thread::ThreadPool
1919
});
2020

2121
suite.addTest("1 task with future.wait()", [&] {
22-
auto called = std::atomic<bool>{false};
22+
auto called = std::atomic_bool{false};
2323
{
2424
auto threadPool = CppUtils::Thread::ThreadPool{};
2525
auto future = threadPool.call([&called] {
@@ -31,7 +31,7 @@ export namespace CppUtils::UnitTest::Thread::ThreadPool
3131
});
3232

3333
suite.addTest("1 task without future.wait()", [&] {
34-
auto called = std::atomic<bool>{false};
34+
auto called = std::atomic_bool{false};
3535
{
3636
auto threadPool = CppUtils::Thread::ThreadPool{};
3737
auto future = threadPool.call([&called] {

tests/Type/Tuple.mpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export namespace CppUtils::UnitTest::Type::Tuple
99
using Logger = CppUtils::Logger<"CppUtils">;
1010

1111
suite.addTest("visitAt", [&] {
12-
auto called = std::atomic<bool>{false};
12+
auto called = std::atomic_bool{false};
1313
auto function = [&called](auto&& value) {
1414
Logger::print<"detail">("{}", value);
1515
called = true;

xmake.lua

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,11 @@ add_rules(
2828
"mode.check",
2929
"mode.profile",
3030
"mode.coverage",
31-
"mode.valgrind")
32-
33-
if is_mode("debug") then
34-
set_policy("build.sanitizer.address", true)
35-
set_policy("build.sanitizer.thread", true)
36-
set_policy("build.sanitizer.undefined", true)
37-
end
31+
"mode.valgrind",
32+
"mode.asan",
33+
"mode.tsan",
34+
"mode.lsan",
35+
"mode.ubsan")
3836

3937
option("enable_tests")
4038
option("enable_moduleonly", {default = true})

0 commit comments

Comments
 (0)