-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
175 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* Copyright (c) 2023 Krisztián Rugási. Subject to the MIT License. */ | ||
|
||
#ifndef GA_UTILITY_ATOMIC_HPP | ||
#define GA_UTILITY_ATOMIC_HPP | ||
|
||
#include <atomic> | ||
#include <memory> | ||
#include <utility> | ||
|
||
namespace gapp::detail | ||
{ | ||
/* | ||
* This is a simple wrapper class around std::atomic with atomic | ||
* initialization, in order to prevent data races between the | ||
* initialization of the variable and later accesses to it. | ||
* | ||
* The wrapper also adds move operators for convenience. | ||
*/ | ||
template<typename T> | ||
class atomic | ||
{ | ||
public: | ||
atomic(std::memory_order order = std::memory_order_seq_cst) noexcept | ||
{ | ||
data_.store(T{}, order); | ||
} | ||
|
||
atomic(T value, std::memory_order order = std::memory_order_seq_cst) noexcept | ||
{ | ||
data_.store(std::move(value), order); | ||
} | ||
|
||
atomic(atomic<T>&& other) noexcept | ||
{ | ||
data_.store(other->load()); | ||
} | ||
|
||
atomic<T>& operator=(T value) noexcept | ||
{ | ||
data_.store(std::move(value)); | ||
return *this; | ||
} | ||
|
||
atomic<T>& operator=(atomic<T>&& other) noexcept | ||
{ | ||
data_.store(other->load()); | ||
return *this; | ||
} | ||
|
||
~atomic() noexcept = default; // maybe needs release? | ||
|
||
std::atomic<T>& operator*() noexcept { return data_; } | ||
std::atomic<T>* operator->() noexcept { return std::addressof(data_); } | ||
const std::atomic<T>& operator*() const noexcept { return data_; } | ||
const std::atomic<T>* operator->() const noexcept { return std::addressof(data_); } | ||
|
||
private: | ||
std::atomic<T> data_; | ||
}; | ||
|
||
|
||
} // namespace gapp::detail | ||
|
||
#endif // !GA_UTILITY_ATOMIC_HPP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
find_package(Catch2 3 REQUIRED) | ||
|
||
if(MSVC) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -wd4388") | ||
endif() | ||
|
||
file(GLOB_RECURSE TEST_SOURCES CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp") | ||
file(GLOB_RECURSE TEST_HEADERS CONFIGURE_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/*.hpp") | ||
|
||
add_executable(tsan_tests ${TEST_SOURCES} ${TEST_HEADERS}) | ||
|
||
target_link_libraries(tsan_tests PRIVATE Catch2::Catch2WithMain gapp) | ||
|
||
include(Catch) | ||
catch_discover_tests(tsan_tests) |
Oops, something went wrong.