Skip to content
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
66 changes: 66 additions & 0 deletions .github/workflows/gtest.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: gtest

on:
- push
- pull_request

jobs:
gtest:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Figure out version
id: tag
run: |
TAG=$(git describe --tags --abbrev=0)
COMMITS_SINCE_TAG=$(git rev-list ${TAG}..HEAD --count)
if [ "${COMMITS_SINCE_TAG}" -eq 0 ]; then
echo "VERSION=${TAG}" >> $GITHUB_ENV
else
echo "VERSION="$(git describe --tags --abbrev=8) >> $GITHUB_ENV
fi
- name: Cache Conan2 dependencies
uses: actions/cache@v3
with:
path: ~/.conan2
key: ${{ runner.os }}-conan2-${{ hashFiles('**/conanfile.py') }}
restore-keys: |
${{ runner.os }}-conan2-
- name: Set up Python 3.8 for gcovr
uses: actions/setup-python@v4
- name: SonarQube install
uses: SonarSource/sonarcloud-github-c-cpp@v3
- name: Install Conan
run: pip install conan
- name: Configure Conan Profile
run: |
conan profile detect -e
conan remote add conan-nexus https://nexus.cridland.io/repository/dwd-conan --force
conan remote login conan-nexus ci --password ${{ secrets.NEXUS_PASSWORD }}
- name: Conan Deps (Debug)
run: conan install . -s build_type=Debug -s compiler.cppstd=gnu23 -b missing --version=${{ env.VERSION }}
- name: Conan Deps (Debug)
run: conan install . -s build_type=Debug -s compiler.cppstd=gnu23 -b missing --version=${{ env.VERSION }}
- name: Conan Deps (Release)
run: conan install . -s build_type=Release -s compiler.cppstd=gnu23 -b missing --version=${{ env.VERSION }}
- name: Conan Deps (RelWithDebInfo)
run: conan install . -s build_type=RelWithDebInfo -s compiler.cppstd=gnu23 -b missing --version=${{ env.VERSION }}
- name: Conan Deps (Debug+Tests)
run: conan install . -o tests=True -s build_type=Debug -s compiler.cppstd=gnu23 -b missing --version=${{ env.VERSION }}
- name: CMake tests
run: cmake -B gh-build -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PROJECT_TOP_LEVEL_INCLUDES="conan_provider.cmake" -DCONAN_INSTALL_ARGS="-o=tests=True;--settings=compiler.cppstd=gnu23;--build=missing;--version=${{ env.VERSION }}"
- name: Build
run: cmake --build gh-build
- name: Run Tests
run: cd gh-build && ./sigslot-test
- name: Create package (Debug)
run: conan create . -s build_type=Debug -s compiler.cppstd=gnu23 -b missing --version=${{ env.VERSION }}
- name: Create package (Release)
run: conan create . -s build_type=Release -s compiler.cppstd=gnu23 -b missing --version=${{ env.VERSION }}
- name: Create package (RelWithDebInfo)
run: conan create . -s build_type=RelWithDebInfo -s compiler.cppstd=gnu23 -b missing --version=${{ env.VERSION }}
- name: Upload
run: conan upload -r conan-nexus --confirm 'st-sigslot/*'
36 changes: 8 additions & 28 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,24 @@ project(sigslot)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

include(FetchContent)
FetchContent_Declare(
googletest
URL https://github.com/google/googletest/archive/03597a01ee50ed33e9dfd640b249b4be3799d395.zip
)
FetchContent_MakeAvailable(googletest)

find_package(GTest)
find_package(sentry)
enable_testing()
link_libraries(GTest::gtest_main)
include_directories(${CMAKE_CURRENT_SOURCE_DIR})
add_executable(sigslot-test
test/sigslot.cc
test/coroutine.cc
sigslot/sigslot.h
sigslot/tasklet.h
sigslot/resume.h
)
add_executable(sigslot-test-resume
sigslot/sigslot.h
sigslot/tasklet.h
test/resume.cc
sigslot/resume.h
)
add_executable(sigslot-test-cothread
sigslot/sigslot.h
sigslot/tasklet.h
test/cothread.cc
sigslot/resume.h
sigslot/cothread.h
test/main.cpp
)
target_link_libraries(sigslot-test PUBLIC gtest::gtest sentry-native::sentry-native)
target_include_directories(sigslot-test SYSTEM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})
target_compile_definitions(sigslot-test PRIVATE DWD_GTEST_SENTRY=1)
include(GoogleTest)
gtest_discover_tests(sigslot-test)
gtest_discover_tests(sigslot-test-resume)
gtest_discover_tests(sigslot-test-cothread)

if (UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fcoroutines")
endif ()
if (WIN32)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /await")
endif()

install(DIRECTORY sigslot TYPE INCLUDE)
24 changes: 2 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ Various patches and fixes applied by Cat Nap Games:
To make this compile under Xcode 4.3 with Clang 3.0 I made some changes myself and also used some diffs published in the original project's Sourceforge forum.
I don't remember which ones though.

C++11-erization (and C++2x-erixation, and mini coroutine library) by Dave Cridland:
C++11-erization (and C++2x-erixation) by Dave Cridland:

See example.cc and co_example.cc for some documentation and a walk-through example, or read the tests.
See example.cc for some documentation and a walk-through example, or read the tests.

This is public domain; no copyright is claimed or asserted.

Expand All @@ -34,23 +34,3 @@ Loosely, calling "emit(...)" on the signal will then call all the connected "slo
If a class is derived (publicly) from has_slots, you can pass in the instance of the class you want to control the lifetime. For calling a specific member directly, that's an easy decision; but if you pass in a lambda or some other arbitrary function, it might not be.

If there's nothing obvious to hand, something still needs to control the scope - leaving out the has_slots argument therefore returns you a (deliberately undocumented) placeholder class, which acts in lieu of a has_slots derived class of your choice.

<sigslot/tasklet.h>

This has a somewhat integrated coroutine library. Tasklets are coroutines, and like most coroutines they can be started, resumed, etc. There's no generator defined, just simple coroutines.

Tasklets expose co_await, so can be awaited by other coroutines. Signals can also be awaited upon, and will resolve to nothing (ie, void), or the single type, or a std::tuple of the types.

<sigslot/resume.h>

Coroutine resumption can be tricky, and is usually best integrated into some kind of event loop. Failure to do so will make it very hard to do anything that you couldn't do as well (or better!) without.

You can define your own resume function which will be called when a coroutine should be resumed, a trivial (and rather poor) example is at the beginning of the co_thread tests.

If you don't, then std::coroutine_handle<>::resume() will be called directly (which works for trivial cases, but not for anything useful).

<sigslot/cothread.h>

sigslot::co_thread is a convenient (but very simple) wrapper to run a non-coroutine in a std::jthread, but outwardly behave as a coroutine. Construct once, and it can be treated as a coroutine definition thereafter, and called multiple times.

This will not work with the built-in resumption, you'll need to implement *some* kind of event loop.
117 changes: 0 additions & 117 deletions co_example.cc

This file was deleted.

Loading
Loading