Skip to content
Draft
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
1 change: 1 addition & 0 deletions include/condy.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "condy/channel.hpp" // IWYU pragma: export
#include "condy/coro.hpp" // IWYU pragma: export
#include "condy/cqe_handler.hpp" // IWYU pragma: export
#include "condy/execution.hpp" // IWYU pragma: export
#include "condy/futex.hpp" // IWYU pragma: export
#include "condy/helpers.hpp" // IWYU pragma: export
#include "condy/pmr.hpp" // IWYU pragma: export
Expand Down
40 changes: 31 additions & 9 deletions include/condy/channel.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

#pragma once

#include <version>

#include "condy/detail/context.hpp"
#include "condy/detail/intrusive.hpp"
#include "condy/detail/invoker.hpp"
Expand All @@ -20,6 +22,9 @@
#include <new>
#include <optional>
#include <type_traits>
#if defined(__cpp_lib_senders)
#include "condy/detail/execution.hpp"
#endif

namespace condy {

Expand Down Expand Up @@ -52,6 +57,11 @@ template <typename T, size_t N = 2> class Channel {

CONDY_DELETE_COPY_MOVE(Channel);

private:
class [[nodiscard]] MovePushSenderImpl;
class [[nodiscard]] CopyPushSenderImpl;
class [[nodiscard]] PopSenderImpl;

public:
/**
* @brief Try to push an item into the channel.
Expand Down Expand Up @@ -111,7 +121,11 @@ template <typename T, size_t N = 2> class Channel {
push_awaiters_.push_back(fake_handle);
}

class [[nodiscard]] MovePushSender;
#if defined(__cpp_lib_senders)
using MovePushSender = detail::StandardSender<MovePushSenderImpl>;
#else
using MovePushSender = MovePushSenderImpl;
#endif
/**
* @brief Push an item into the channel, awaiting if necessary.
* @param item The item to be pushed into the channel.
Expand All @@ -126,7 +140,11 @@ template <typename T, size_t N = 2> class Channel {
*/
MovePushSender push(T &&item) noexcept { return {*this, std::move(item)}; }

class [[nodiscard]] CopyPushSender;
#if defined(__cpp_lib_senders)
using CopyPushSender = detail::StandardSender<CopyPushSenderImpl>;
#else
using CopyPushSender = CopyPushSenderImpl;
#endif
/**
* @brief Push an item into the channel, awaiting if necessary.
* @param item The item to be pushed into the channel.
Expand All @@ -140,7 +158,11 @@ template <typename T, size_t N = 2> class Channel {
return {*this, item};
}

class [[nodiscard]] PopSender;
#if defined(__cpp_lib_senders)
using PopSender = detail::StandardSender<PopSenderImpl>;
#else
using PopSender = PopSenderImpl;
#endif
/**
* @brief Pop an item from the channel, awaiting if necessary.
* @return std::pair<int32_t, T> 0 and the popped item if successful; -EPIPE
Expand Down Expand Up @@ -529,12 +551,12 @@ class Channel<T, N>::PopFinishHandle
std::optional<StopCallbackType> stop_callback_;
};

template <typename T, size_t N> class Channel<T, N>::MovePushSender {
template <typename T, size_t N> class Channel<T, N>::MovePushSenderImpl {
public:
using CondySender = void;
using ReturnType = int32_t;

MovePushSender(Channel &channel, T &&item)
MovePushSenderImpl(Channel &channel, T &&item)
: channel_(channel), item_(std::move(item)) {}

template <typename Receiver> auto connect_impl(Receiver receiver) noexcept {
Expand Down Expand Up @@ -562,12 +584,12 @@ template <typename T, size_t N> class Channel<T, N>::MovePushSender {
T &&item_;
};

template <typename T, size_t N> class Channel<T, N>::CopyPushSender {
template <typename T, size_t N> class Channel<T, N>::CopyPushSenderImpl {
public:
using CondySender = void;
using ReturnType = int32_t;

CopyPushSender(Channel &channel, const T &item)
CopyPushSenderImpl(Channel &channel, const T &item)
: channel_(channel), item_(item) {}

template <typename Receiver> auto connect_impl(Receiver receiver) noexcept {
Expand Down Expand Up @@ -598,12 +620,12 @@ template <typename T, size_t N> class Channel<T, N>::CopyPushSender {
const T &item_;
};

template <typename T, size_t N> class Channel<T, N>::PopSender {
template <typename T, size_t N> class Channel<T, N>::PopSenderImpl {
public:
using CondySender = void;
using ReturnType = std::pair<int32_t, T>;

PopSender(Channel &channel) : channel_(channel) {}
PopSenderImpl(Channel &channel) : channel_(channel) {}

template <typename Receiver> auto connect_impl(Receiver receiver) noexcept {
return OperationState<Receiver>(channel_, std::move(receiver));
Expand Down
Loading
Loading