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
47 changes: 47 additions & 0 deletions .github/workflows/cmake_modules.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: CMake_cpp20_modules

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release

jobs:
build_with_clang:
strategy:
matrix:
clang_version: [20, 21]
# The CMake configure and build commands are platform agnostic and should work equally well on Windows or Mac.
# You can convert this to a matrix build if you need cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-22.04

steps:
- uses: actions/checkout@v2

- name: deps
run: |
sudo apt update
wget https://apt.llvm.org/llvm.sh
chmod +x ./llvm.sh
sudo ./llvm.sh ${{matrix.clang_version}}
sudo apt install libaio-dev libgtest-dev libgmock-dev ninja-build/jammy -y

- name: Configure CMake
# Configure CMake in a 'build' subdirectory. `CMAKE_BUILD_TYPE` is only required if you are using a single-configuration generator such as make.
# See https://cmake.org/cmake/help/latest/variable/CMAKE_BUILD_TYPE.html?highlight=cmake_build_type
run: CXX=clang++-${{matrix.clang_version}} CC=clang-${{matrix.clang_version}} cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DASYNC_SIMPLE_BUILD_MODULES=ON -GNinja

- name: Build
# Build your program with the given configuration
run: cd ${{github.workspace}}/build && ninja -j 9

- name: Test
working-directory: ${{github.workspace}}/build
# Execute tests defined by the CMake configuration.
# See https://cmake.org/cmake/help/latest/manual/ctest.1.html for more detail
run: ctest -C ${{env.BUILD_TYPE}} --output-on-failure
6 changes: 3 additions & 3 deletions async_simple/Signal.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ class Signal : public std::enable_shared_from_this<Signal> {
// binding slots, then execute the slot callback functions. It will return
// the signal which success triggered. If no signal success triggger, return
// SignalType::none.
SignalType emit(SignalType state) noexcept;
SignalType emits(SignalType state) noexcept;

// Return now signal type.
SignalType state() const noexcept {
Expand Down Expand Up @@ -320,7 +320,7 @@ class Slot {
[chainedSignal =
chainedSignal->weak_from_this()](SignalType type) {
if (auto signal = chainedSignal.lock(); signal != nullptr) {
signal->emit(type);
signal->emits(type);
}
}),
std::memory_order_release);
Expand Down Expand Up @@ -451,7 +451,7 @@ inline detail::SignalSlotSharedState::~SignalSlotSharedState() {
}
}

inline SignalType Signal::emit(SignalType state) noexcept {
inline SignalType Signal::emits(SignalType state) noexcept {
if (state != SignalType::None) {
SignalType vaildSignal = UpdateState(_state, state);
if (vaildSignal) {
Expand Down
15 changes: 12 additions & 3 deletions async_simple/async_simple.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,30 @@ module;
#include <stdio.h>
#include <cassert>
#include <climits>
#include <cstdint>
#include <version>

#ifdef __linux__
#include <sched.h>
#endif

#if __has_include(<libaio.h>) && !defined(ASYNC_SIMPLE_HAS_NOT_AIO)
#include <libaio.h>
#endif

export module async_simple;
import std;
#define ASYNC_SIMPLE_USE_MODULES
export extern "C++" {
#include "util/move_only_function.h"
#include "coro/Traits.h"
#include "CommonMacros.h"
#include "Common.h"
#include "MoveWrapper.h"
#include "experimental/coroutine.h"
#include "async_simple/Signal.h"
#include "Executor.h"
#include "CommonMacros.h"
#include "Common.h"
#include "async_simple/coro/LazyLocalBase.h"
#include "Unit.h"
#include "Try.h"
#include "FutureState.h"
Expand All @@ -41,6 +48,9 @@ export extern "C++" {
#include "Promise.h"
#include "coro/DetachedCoroutine.h"
#include "coro/ViaCoroutine.h"
#if defined(__clang_major__) && __clang_major__ >= 17
#include "coro/PromiseAllocator.h"
#endif
#include "coro/Lazy.h"
#include "uthread/internal/thread_impl.h"
#include "uthread/Await.h"
Expand Down Expand Up @@ -71,7 +81,6 @@ export extern "C++" {
#include "coro/Semaphore.h"
// There are some bugs in clang lower versions.
#if defined(__clang_major__) && __clang_major__ >= 17
#include "coro/PromiseAllocator.h"
#include "coro/Generator.h"
#endif
}
8 changes: 4 additions & 4 deletions async_simple/coro/Collect.h
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ struct CollectAnyAwaiter {
_result->_idx = i;
_result->_value = std::move(result);
if (auto ptr = local->getSlot(); ptr) {
ptr->signal()->emit(_SignalType);
ptr->signal()->emits(_SignalType);
}
c.resume();
}
Expand Down Expand Up @@ -294,7 +294,7 @@ struct CollectAnyVariadicAwaiter {
_result = std::make_unique<ResultType>(
std::in_place_index_t<index>(), std::move(res));
if (auto ptr = local->getSlot(); ptr) {
ptr->signal()->emit(_SignalType);
ptr->signal()->emits(_SignalType);
}
c.resume();
}
Expand Down Expand Up @@ -409,7 +409,7 @@ struct CollectAllAwaiter {
auto signalType = _SignalType;
auto awaitingCoro = _event.down(oldCount, 1);
if (oldCount == size) {
signal->emit(signalType);
signal->emits(signalType);
}
if (awaitingCoro) {
awaitingCoro.resume();
Expand Down Expand Up @@ -582,7 +582,7 @@ struct CollectAllVariadicAwaiter {
auto signalType = _SignalType;
auto awaitingCoro = _event.down(oldCount, 1);
if (oldCount == sizeof...(Ts)) {
signal->emit(signalType);
signal->emits(signalType);
}
if (awaitingCoro) {
awaitingCoro.resume();
Expand Down
3 changes: 2 additions & 1 deletion async_simple/coro/Lazy.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@
#ifndef ASYNC_SIMPLE_CORO_LAZY_H
#define ASYNC_SIMPLE_CORO_LAZY_H

#include <system_error>

#ifndef ASYNC_SIMPLE_USE_MODULES

#include <cstddef>
#include <system_error>
#include <cstdio>
#include <exception>
#include <memory>
Expand Down
6 changes: 3 additions & 3 deletions async_simple/coro/test/LazyTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ TEST_F(LazyTest, testYieldCancel) {
EXPECT_EQ(result.hasError(), true);
p.set_value();
});
signal->emit(SignalType::Terminate);
signal->emits(SignalType::Terminate);
p.get_future().wait();
}

Expand Down Expand Up @@ -2020,7 +2020,7 @@ TEST_F(LazyTest, testForbiddenCancel) {
EXPECT_EQ(slot->signal()->state(), SignalType::Terminate);
};
lazy(p.getFuture()).setLazyLocal(signal.get()).via(&e).detach();
signal->emit(SignalType::Terminate);
signal->emits(SignalType::Terminate);
p.setValue();
}
{
Expand All @@ -2037,7 +2037,7 @@ TEST_F(LazyTest, testForbiddenCancel) {
EXPECT_EQ(slot, nullptr);
};
lazy(p.getFuture()).setLazyLocal(signal.get()).via(&e).detach();
signal->emit(SignalType::Terminate);
signal->emits(SignalType::Terminate);
p.setValue();
}
}
Expand Down
2 changes: 1 addition & 1 deletion async_simple/coro/test/SleepTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ Lazy<void> cancelSleep() {
EXPECT_TRUE(err.value() == async_simple::Terminate);
}
auto slot = co_await async_simple::coro::CurrentSlot{};
auto ok = slot->signal()->emit(SignalType::Terminate);
auto ok = slot->signal()->emits(SignalType::Terminate);
if (ok) {
std::cout << "Coro " << i << " emit cancel work" << std::endl;
} else {
Expand Down
4 changes: 2 additions & 2 deletions async_simple/coro/test/SpinLockTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ TEST_F(SpinLockTest, testSpinLockCancel) {
auto signal = async_simple::Signal::create();
std::promise<void> p;
if (cancelFirst) {
signal->emit(SignalType::Terminate);
signal->emits(SignalType::Terminate);
}
std::move(lazy)
.setLazyLocal(signal.get())
Expand All @@ -132,7 +132,7 @@ TEST_F(SpinLockTest, testSpinLockCancel) {
});
if (!cancelFirst) {
std::this_thread::sleep_for(10ms);
signal->emit(SignalType::Terminate);
signal->emits(SignalType::Terminate);
}
p.get_future().wait();
};
Expand Down
8 changes: 8 additions & 0 deletions async_simple/std.mock.cppm
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ module;
#include <exception>
#include <fstream>
#include <functional>
#include <future>
#include <iostream>
#include <iterator>
#include <limits>
Expand Down Expand Up @@ -1855,6 +1856,13 @@ using std::operator<<;
using std::hash;
} // namespace std

export namespace std {
using std::popcount;
using std::countr_zero;
using std::promise;
using std::unordered_map;
}

#if defined(__GLIBCXX__) || defined(__GLIBCPP__)
export namespace __gnu_cxx {
using __gnu_cxx::operator==;
Expand Down
Loading