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
14 changes: 7 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ target_compile_options(ustdex INTERFACE
$<$<COMPILE_LANG_AND_ID:CXX,MSVC>:/Zc:__cplusplus /Zc:hiddenFriend /Zc:preprocessor /Zc:externConstexpr>)

# download CPM.cmake
file(
DOWNLOAD
https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.39.0/CPM.cmake
${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake
EXPECTED_HASH SHA256=66639bcac9dd2907b2918de466783554c1334446b9874e90d38e3778d404c2ef
)
include(${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake)
#file(
# DOWNLOAD
# https://github.com/cpm-cmake/CPM.cmake/releases/download/v0.39.0/CPM.cmake
# ${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake
# EXPECTED_HASH SHA256=66639bcac9dd2907b2918de466783554c1334446b9874e90d38e3778d404c2ef
#)
#include(${CMAKE_CURRENT_BINARY_DIR}/cmake/CPM.cmake)

if (USTDEX_ENABLE_CUDA)
target_compile_features(ustdex INTERFACE cuda_std_17)
Expand Down
85 changes: 54 additions & 31 deletions CMakePresets.json
Original file line number Diff line number Diff line change
@@ -1,36 +1,59 @@
{
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 21,
"patch": 3
"version": 3,
"cmakeMinimumRequired": {
"major": 3,
"minor": 21,
"patch": 3
},
"configurePresets": [
{
"name": "Debug",
"binaryDir": "${sourceDir}/build/Debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_CXX_STANDARD": "17",
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG}/scripts/buildsystems/vcpkg.cmake"
}
},
"configurePresets": [
{
"name": "Debug",
"binaryDir": "${sourceDir}/build/Debug",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_CXX_STANDARD": "17"
}
{
"name": "Release",
"binaryDir": "${sourceDir}/build/Release",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_CXX_STANDARD": "17",
"CMAKE_TOOLCHAIN_FILE": "$env{VCPKG}/scripts/buildsystems/vcpkg.cmake"
}
},
{
"name": "clang-x64-debug",
"displayName": "Clang x64 Debug",
"binaryDir": "${sourceDir}/out/build/${presetName}",
"installDir": "${sourceDir}/out/install/${presetName}",
"architecture": {
"value": "x64",
"strategy": "external"
},
{
"name": "Release",
"binaryDir": "${sourceDir}/build/Release",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Release",
"CMAKE_CXX_STANDARD": "17"
"cacheVariables": {
"CMAKE_C_COMPILER": "clang.exe",
"CMAKE_CXX_COMPILER": "clang++.exe",
"CMAKE_BUILD_TYPE": "Debug"
},
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"intelliSenseMode": "windows-clang-x64"
}
}
],
"buildPresets": [
{
"name": "Debug",
"configurePreset": "Debug"
},
{
"name": "Release",
"configurePreset": "Release"
}
]
}
}
],
"buildPresets": [
{
"name": "Debug",
"configurePreset": "Debug"
},
{
"name": "Release",
"configurePreset": "Release"
},

]
}
4 changes: 4 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@
# See the License for the specific language governing permissions and
# limitations under the License.


#find_package(asio CONFIG REQUIRED)

add_executable(_clangd_helper_file detail/_clangd_helper_file.cpp)
target_link_libraries(_clangd_helper_file PUBLIC ustdex)

add_executable(scratch scratch.cpp)
target_link_libraries(scratch PUBLIC ustdex)
#target_link_libraries(scratch PUBLIC ustdex asio::asio)

if (USTDEX_ENABLE_CUDA)
add_executable(cuscratch scratch.cu)
Expand Down
135 changes: 135 additions & 0 deletions examples/asio_thread_pool.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#pragma once

#include <ustdex/ustdex.hpp>
#include <asio.hpp>

namespace atp
{
template <class Rcvr>
struct _operation
{
asio::any_io_executor _executor_;
USTDEX_NO_UNIQUE_ADDRESS Rcvr _rcvr_;

USTDEX_API static void _execute_impl(_operation* _p) noexcept
{
auto& _rcvr = _p->_rcvr_;
try
{
if (ustdex::get_stop_token(ustdex::get_env(_rcvr)).stop_requested())
{
ustdex::set_stopped(static_cast<Rcvr&&>(_rcvr));
}
else
{
ustdex::set_value(static_cast<Rcvr&&>(_rcvr));
}
}
catch (...)
{
ustdex::set_error(static_cast<Rcvr&&>(_rcvr), ::std::current_exception());
}

}

USTDEX_API _operation(asio::any_io_executor executor, Rcvr _rcvr) :
_executor_{ executor }
, _rcvr_{ static_cast<Rcvr&&>(_rcvr) }
{}

USTDEX_API void start() & noexcept;
};

class asio_scheduler
{
struct _schedule_task
{
using sender_concept = ustdex::sender_t;

template <class Rcvr>
USTDEX_API auto connect(Rcvr _rcvr) const noexcept -> _operation<Rcvr>
{
return { _executor_, static_cast<Rcvr&&>(_rcvr) };
}

template <class Self>
USTDEX_API static constexpr auto get_completion_signatures() noexcept
{
return ustdex::completion_signatures<ustdex::set_value_t(), ustdex::set_error_t(::std::exception_ptr), ustdex::set_stopped_t()>();
}

private:
friend asio_scheduler;

struct _env
{
asio::any_io_executor _executor_;

template <class Tag>
USTDEX_API auto query(ustdex::get_completion_scheduler_t<Tag>) const noexcept -> asio_scheduler
{
return asio_scheduler{ _executor_ };
}
};

USTDEX_API auto get_env() const noexcept -> _env
{
return _env{ _executor_ };
}

USTDEX_API explicit _schedule_task(asio::any_io_executor executor) noexcept
: _executor_(executor)
{}

asio::any_io_executor const _executor_;
};

USTDEX_API auto query(ustdex::get_forward_progress_guarantee_t) const noexcept -> ustdex::forward_progress_guarantee
{
return ustdex::forward_progress_guarantee::parallel;
}

asio::any_io_executor _executor_;

public:
using scheduler_concept = ustdex::scheduler_t;

USTDEX_API explicit asio_scheduler(asio::any_io_executor executor) noexcept
: _executor_(executor)
{}

[[nodiscard]] USTDEX_API auto schedule() const noexcept -> _schedule_task
{
return _schedule_task{ _executor_ };
}

USTDEX_API friend bool operator==(const asio_scheduler& _a, const asio_scheduler& _b) noexcept
{
return _a._executor_ == _b._executor_;
}

USTDEX_API friend bool operator!=(const asio_scheduler& _a, const asio_scheduler& _b) noexcept
{
return _a._executor_ != _b._executor_;
}
};

template <class Rcvr>
USTDEX_API inline void _operation<Rcvr>::start() & noexcept
{
try
{
asio::post(_executor_,
[this]()
{
_execute_impl(this);
});
}
catch(...)
{
ustdex::set_error(static_cast<Rcvr&&>(_rcvr_), ::std::current_exception());
}

}

}
Loading
Loading