8000 Fix: Move platform-agnostic files outside of `LIBCORO_FEATURE_THREADING` by bjones1 · Pull Request #175 · jbaldwin/libcoro · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix: Move platform-agnostic files outside of LIBCORO_FEATURE_THREADING #175

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 7 commits into from
Oct 12, 2023
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
25 changes: 12 additions & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,37 +55,36 @@ endif()

set(LIBCORO_SOURCE_FILES
include/coro/concepts/awaitable.hpp
include/coro/concepts/buffer.hpp
include/coro/concepts/executor.hpp
include/coro/concepts/promise.hpp
include/coro/concepts/range_of.hpp

include/coro/detail/void_value.hpp

include/coro/attribute.hpp
include/coro/coro.hpp
include/coro/event.hpp src/event.cpp
include/coro/generator.hpp
include/coro/latch.hpp
include/coro/mutex.hpp src/mutex.cpp
include/coro/ring_buffer.hpp
include/coro/semaphore.hpp src/semaphore.cpp
include/coro/shared_mutex.hpp
include/coro/sync_wait.hpp src/sync_wait.cpp
include/coro/task.hpp
include/coro/task_container.hpp
include/coro/thread_pool.hpp src/thread_pool.cpp
include/coro/when_all.hpp
)

if(LIBCORO_FEATURE_THREADING)
list(APPEND LIBCORO_SOURCE_FILES
include/coro/concepts/buffer.hpp
include/coro/concepts/executor.hpp
include/coro/concepts/range_of.hpp

include/coro/detail/poll_info.hpp

include/coro/event.hpp src/event.cpp
include/coro/fd.hpp
include/coro/io_scheduler.hpp src/io_scheduler.cpp
include/coro/latch.hpp
include/coro/mutex.hpp src/mutex.cpp
include/coro/poll.hpp
include/coro/ring_buffer.hpp
include/coro/semaphore.hpp src/semaphore.cpp
include/coro/shared_mutex.hpp
include/coro/sync_wait.hpp src/sync_wait.cpp
include/coro/task_container.hpp
include/coro/thread_pool.hpp src/thread_pool.cpp
)
endif()

Expand Down
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -849,10 +849,13 @@ int main()
// Connect to the server.
co_await client.connect();

// Make sure the client socket can be written to.
co_await client.poll(coro::poll_op::write);

// Send the request data.
client.send(std::string_view{"Hello from client."});

// Wait for the response an receive it.
// Wait for the response and receive it.
co_await client.poll(coro::poll_op::read);
std::string response(256, '\0');
auto [recv_status, recv_bytes] = client.recv(response);
Expand Down Expand Up @@ -914,6 +917,9 @@ int main()
request.resize(recv_bytes.size());
std::cout << "server: " << request << "\n";

// Make sure the client socket can be written to.
co_await client.poll(coro::poll_op::write);

auto response = "Hello from server " + std::to_string(requests);
client.send(response);

Expand Down Expand Up @@ -951,6 +957,9 @@ int main()
// Send N requests on the same connection and wait for the server response to each one.
for (size_t i = 1; i <= request_count; ++i)
{
// Make sure the client socket can be written to.
co_await client.poll(coro::poll_op::write);

// Send the request data.
auto request = "Hello from client " + std::to_string(i);
client.send(request);
Expand Down
24 changes: 12 additions & 12 deletions include/coro/coro.hpp
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
#pragma once

#include "coro/concepts/awaitable.hpp"
#include "coro/concepts/buffer.hpp"
#include "coro/concepts/executor.hpp"
#include "coro/concepts/promise.hpp"
#include "coro/concepts/range_of.hpp"

#ifdef LIBCORO_FEATURE_THREADING
#include "coro/concepts/buffer.hpp"
#include "coro/concepts/executor.hpp"
#include "coro/concepts/range_of.hpp"
#include "coro/event.hpp"
#include "coro/io_scheduler.hpp"
#include "coro/latch.hpp"
#include "coro/mutex.hpp"
#include "coro/poll.hpp"
#include "coro/ring_buffer.hpp"
#include "coro/semaphore.hpp"
#include "coro/shared_mutex.hpp"
#include "coro/sync_wait.hpp"
#include "coro/task_container.hpp"
#include "coro/thread_pool.hpp"
#endif

#ifdef LIBCORO_FEATURE_NETWORKING
Expand All @@ -36,6 +27,15 @@
#include "coro/net/udp_peer.hpp"
#endif

#include "coro/event.hpp"
#include "coro/generator.hpp"
#include "coro/latch.hpp"
#include "coro/mutex.hpp"
#include "coro/ring_buffer.hpp"
#include "coro/semaphore.hpp"
#include "coro/shared_mutex.hpp"
#include "coro/sync_wait.hpp"
#include "coro/task.hpp"
#include "coro/task_container.hpp"
#include "coro/thread_pool.hpp"
#include "coro/when_all.hpp"
11 changes: 8 additions & 3 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ cmake_minimum_required(VERSION 3.0)
project(libcoro_test)

set(LIBCORO_TEST_SOURCE_FILES
bench.cpp
test_event.cpp
test_generator.cpp
test_io_scheduler.cpp
test_latch.cpp
test_mutex.cpp
test_ring_buffer.cpp
Expand All @@ -28,6 +26,13 @@ if(LIBCORO_FEATURE_NETWORKING)
)
endif()

if(LIBCORO_FEATURE_THREADING)
list(APPEND LIBCORO_TEST_SOURCE_FILES
bench.cpp
test_io_scheduler.cpp
)
endif()

add_executable(${PROJECT_NAME} main.cpp ${LIBCORO_TEST_SOURCE_FILES})
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_20)
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
Expand All @@ -45,4 +50,4 @@ elseif(${CMAKE_CXX_COMPILER_ID} MATCHES "Clang")
message(FATAL_ERROR "Clang is currently not supported.")
endif()

add_test(NAME libcoro_tests COMMAND ${PROJECT_NAME})
add_test(NAME libcoro_tests COMMAND ${PROJECT_NAME})
9 changes: 4 additions & 5 deletions test/test_ring_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,8 @@ TEST_CASE("ring_buffer producer consumer separate threads", "[ring_buffer]")
coro::ring_buffer<uint64_t, 2> rb{};

// We'll use an io schedule so we can use yield_for on shutdown since its two threads.
coro::io_scheduler producer_tp{coro::io_scheduler::options{
.execution_strategy = coro::io_scheduler::execution_strategy_t::process_tasks_inline}};
coro::thread_pool consumer_tp{coro::thread_pool::options{.thread_count = 1}};
coro::thread_pool producer_tp{coro::thread_pool::options{.thread_count = 1}};
coro::thread_pool consumer_tp{coro::thread_pool::options{.thread_count = 1}};

auto make_producer_task = [&]() -> coro::task<void>
{
Expand All @@ -143,7 +142,7 @@ TEST_CASE("ring_buffer producer consumer separate threads", "[ring_buffer]")

while (!rb.empty())
{
co_await producer_tp.yield_for(std::chrono::milliseconds{10});
co_await producer_tp.yield();
}

rb.notify_waiters(); // Shut everything down.
Expand Down Expand Up @@ -178,4 +177,4 @@ TEST_CASE("ring_buffer producer consumer separate threads", "[ring_buffer]")
coro::sync_wait(coro::when_all(std::move(tasks)));

REQUIRE(rb.empty());
}
}
4 changes: 2 additions & 2 deletions test/test_semaphore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ TEST_CASE("semaphore ringbuffer many producers and consumers", "[semaphore]")

coro::semaphore s{50, 0};

coro::io_scheduler tp{}; // let er rip
coro::thread_pool tp{}; // let er rip

auto make_consumer_task = [&](uint64_t id) -> coro::task<void>
{
Expand Down Expand Up @@ -210,7 +210,7 @@ TEST_CASE("semaphore ringbuffer many producers and consumers", "[semaphore]")

while (value.load(std::memory_order::relaxed) < iterations)
{
co_await tp.yield_for(std::chrono::milliseconds{1});
co_await tp.yield();
}

std::cerr << "producer " << id << " exiting\n";
Expand Down
2 changes: 2 additions & 0 deletions test/test_shared_mutex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ TEST_CASE("mutex single waiter not locked shared", "[shared_mutex]")
m.unlock();
}

#ifdef LIBCORO_FEATURE_THREADING
TEST_CASE("mutex many shared and exclusive waiters interleaved", "[shared_mutex]")
{
auto tp = std::make_shared<coro::io_scheduler>(
Expand Down Expand Up @@ -163,3 +164,4 @@ TEST_CASE("mutex many shared and exclusive waiters interleaved", "[shared_mutex]

coro::sync_wait(coro::when_all(make_shared_tasks_task(), make_exclusive_task()));
}
#endif
0