Skip to content
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

Shared library builds #23

Merged
merged 3 commits into from
Jun 3, 2024
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
16 changes: 16 additions & 0 deletions .github/build_profiles/msvc20ds
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[settings]
arch=x86_64
build_type=Debug
compiler=msvc
compiler.cppstd=20
compiler.version=193
compiler.runtime=dynamic
os=Windows

[options]
asyncpp/*:shared=True

[conf]
tools.build:compiler_executables={'c': 'cl.exe', 'cpp': 'cl.exe' }
tools.cmake.cmaketoolchain:generator=Ninja
tools.cmake.cmake_layout:build_folder_vars=["settings.compiler", "settings.compiler.cppstd", "settings.build_type"]
5 changes: 4 additions & 1 deletion .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
build_profile: [clang20d, clang20r, gcc20d, gcc20r, msvc20d, msvc20r]
build_profile: [clang20d, clang20r, gcc20d, gcc20r, msvc20d, msvc20r, msvc20ds]
include:
- build_profile: clang20d
conan_preset: clang-20-debug
Expand All @@ -35,6 +35,9 @@ jobs:
- build_profile: msvc20r
conan_preset: msvc-20-release
os: windows-latest
- build_profile: msvc20ds
conan_preset: msvc-20-debug
os: windows-latest

name: ${{ matrix.build_profile }}

Expand Down
10 changes: 5 additions & 5 deletions include/asyncpp/testing/interleaver.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ struct thread_state {
return thread_state{ static_cast<code>(reinterpret_cast<size_t>(&sp)) };
}

static constinit const thread_state running;
static constinit const thread_state blocked;
static constinit const thread_state completed;
static constexpr thread_state running() { return thread_state{ code::running }; }
static constexpr thread_state blocked() { return thread_state{ code::blocked }; }
static constexpr thread_state completed() { return thread_state{ code::completed }; }

code value = code::running;
};
Expand All @@ -68,7 +68,7 @@ class thread {
initialize_this_thread();
INTERLEAVED("initial_point");
func(std::forward<Args_>(args_)...);
m_content->state.store(thread_state::completed);
m_content->state.store(thread_state::completed());
};
m_content->thread = std::jthread(wrapper, std::forward<Args>(args)...);
}
Expand All @@ -84,7 +84,7 @@ class thread {
private:
struct content {
std::jthread thread;
std::atomic<thread_state> state = thread_state::running;
std::atomic<thread_state> state = thread_state::running();
};
std::unique_ptr<content> m_content = std::make_unique<content>();
static thread_local thread* current_thread;
Expand Down
4 changes: 3 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ target_sources(asyncpp
semaphore.cpp
)

target_link_libraries(asyncpp asyncpp-headers)
target_link_libraries(asyncpp asyncpp-headers)

set_target_properties(asyncpp PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)
20 changes: 8 additions & 12 deletions src/testing/interleaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@
namespace asyncpp::testing {


constinit const thread_state thread_state::running = thread_state{ code::running };
constinit const thread_state thread_state::blocked = thread_state{ code::blocked };
constinit const thread_state thread_state::completed = thread_state{ code::completed };

static_assert(std::atomic<thread_state>::is_always_lock_free);

thread_local thread* thread::current_thread = nullptr;
Expand All @@ -33,7 +29,7 @@ void thread::resume() {
const auto current_state = m_content->state.load();
const auto current_suspension_point = current_state.get_suspension_point();
assert(current_suspension_point && "thread must be suspended at a suspension point");
const auto next_state = current_suspension_point->acquire ? thread_state::blocked : thread_state::running;
const auto next_state = current_suspension_point->acquire ? thread_state::blocked() : thread_state::running();
m_content->state.store(next_state);
}

Expand All @@ -52,7 +48,7 @@ thread_state thread::get_state() const {

void thread::suspend(const suspension_point& sp) {
const auto prev_state = m_content->state.exchange(thread_state::suspended(sp));
assert(prev_state == thread_state::running || prev_state == thread_state::blocked);
assert(prev_state == thread_state::running() || prev_state == thread_state::blocked());
while (m_content->state.load().is_suspended()) {
// Wait.
}
Expand Down Expand Up @@ -101,13 +97,13 @@ tree::stable_node& tree::previous(transition_node& node) {
std::string dump(const swarm_state& state) {
std::stringstream ss;
for (const auto& th : state.thread_states) {
if (th == thread_state::completed) {
if (th == thread_state::completed()) {
ss << "completed";
}
else if (th == thread_state::blocked) {
else if (th == thread_state::blocked()) {
ss << "blocked";
}
else if (th == thread_state::running) {
else if (th == thread_state::running()) {
ss << "running";
}
else {
Expand Down Expand Up @@ -206,7 +202,7 @@ bool is_stable(const std::vector<thread_state>& states) {


bool is_unblocked(const std::vector<thread_state>& states) {
const auto num_blocked = std::ranges::count_if(states, [](const auto& state) { return state == thread_state::blocked; });
const auto num_blocked = std::ranges::count_if(states, [](const auto& state) { return state == thread_state::blocked(); });
const auto num_suspended = std::ranges::count_if(states, [](const auto& state) { return state.is_suspended(); });
if (num_blocked != 0) {
return num_suspended != 0;
Expand Down Expand Up @@ -249,7 +245,7 @@ bool is_transitively_complete(const tree& tree, const tree::stable_node& node) {
completed_paths.resize(swarm.thread_states.size(), false);
for (size_t resumed = 0; resumed < swarm.thread_states.size(); ++resumed) {
const auto& ts = swarm.thread_states[resumed];
if (ts == thread_state::completed || ts == thread_state::blocked) {
if (ts == thread_state::completed() || ts == thread_state::blocked()) {
completed_paths[resumed] = true;
}
}
Expand Down Expand Up @@ -287,7 +283,7 @@ path run_next_interleaving(tree& tree, std::span<std::unique_ptr<thread>> swarm)
try {
const auto state = swarm_state(stabilize(swarm));
path.steps.push_back({ state, -1 });
if (std::ranges::all_of(state.thread_states, [](const auto& ts) { return ts == thread_state::completed; })) {
if (std::ranges::all_of(state.thread_states, [](const auto& ts) { return ts == thread_state::completed(); })) {
break;
}
for (size_t thread_idx = 0; thread_idx < swarm.size(); ++thread_idx) {
Expand Down
16 changes: 8 additions & 8 deletions test/testing/test_interleaver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ TEST_CASE("Interleaver - next from transition node", "[Interleaver]") {

TEST_CASE("Interleaver - is transitively complete", "[Interleaver]") {
const std::vector initial = { thread_state::suspended(p1) };
const std::vector final = { thread_state::completed };
const std::vector blocked = { thread_state::blocked };
const std::vector final = { thread_state::completed() };
const std::vector blocked = { thread_state::blocked() };

SECTION("empty root node") {
tree t;
Expand Down Expand Up @@ -118,7 +118,7 @@ TEST_CASE("Interleaver - is transitively complete", "[Interleaver]") {
TEST_CASE("Interleaver - mark complete", "[Interleaver]") {
const std::vector at_p1 = { thread_state::suspended(p1) };
const std::vector at_p2 = { thread_state::suspended(p2) };
const std::vector final = { thread_state::completed };
const std::vector final = { thread_state::completed() };

tree t;
auto& n1 = t.root();
Expand All @@ -136,11 +136,11 @@ TEST_CASE("Interleaver - mark complete", "[Interleaver]") {
TEST_CASE("Interleaver - select resumed", "[Interleaver]") {
const std::vector initial = { thread_state::suspended(p3), thread_state::suspended(p3) };
const std::vector both_ready = { thread_state::suspended(p1), thread_state::suspended(p1) };
const std::vector left_ready = { thread_state::suspended(p1), thread_state::completed };
const std::vector right_ready = { thread_state::completed, thread_state::suspended(p1) };
const std::vector none_ready = { thread_state::completed, thread_state::completed };
const std::vector left_blocked = { thread_state::blocked, thread_state::suspended(p1) };
const std::vector right_blocked = { thread_state::suspended(p1), thread_state::blocked };
const std::vector left_ready = { thread_state::suspended(p1), thread_state::completed() };
const std::vector right_ready = { thread_state::completed(), thread_state::suspended(p1) };
const std::vector none_ready = { thread_state::completed(), thread_state::completed() };
const std::vector left_blocked = { thread_state::blocked(), thread_state::suspended(p1) };
const std::vector right_blocked = { thread_state::suspended(p1), thread_state::blocked() };

tree t;
auto& transition = t.next(t.root(), swarm_state(initial));
Expand Down
Loading