From 01fdb5c03bd0fe8ae9dd2f1205822af18ba753ee Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Sun, 2 Nov 2025 23:34:37 +0100 Subject: [PATCH 1/2] First prototypes --- include/cppcore/Concurrent/async.h | 85 ++++++++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 include/cppcore/Concurrent/async.h diff --git a/include/cppcore/Concurrent/async.h b/include/cppcore/Concurrent/async.h new file mode 100644 index 0000000..6c7212d --- /dev/null +++ b/include/cppcore/Concurrent/async.h @@ -0,0 +1,85 @@ +#pragma once + +namespace cppcore { +namespace concurrent { + + enum class AsyncStatus { + Pending, + Running, + Completed, + Failed + }; + + struct context_t { + void *data; + }; + + class Executor { + public: + Executor(); + ~Executor(); + Executor(const Executor&) = delete; + Executor& operator=(const Executor&) = delete; + + void run(); + + bool isRunning() const; + + /** + * @brief Submits a task for asynchronous execution. + * + * @param task The task to be executed. + */ + template + void submit(Task&& task); + + /** + * @brief Shuts down the executor, waiting for all tasks to complete. + */ + void shutdown(); + + private: + }; + + /** + * @brief Asynchronous task representation. + * + * This class provides a mechanism to represent and manage asynchronous tasks. + * It allows for task creation, execution, and result retrieval in a concurrent + * environment. + */ + class AsyncTask { + public: + /** + * @brief Constructs an AsyncTask with the given function. + * + * @param func The function to be executed asynchronously. + */ + template + explicit AsyncTask(Func&& func) { + // Implementation here + } + + /** + * @brief Starts the asynchronous task. + */ + void start(const context_t& ctx = { nullptr }); + + /// @brief + /// @return + AsyncStatus status() const; + + /** + * @brief Waits for the task to complete and retrieves the result. + * + * @return The result of the asynchronous task. + */ + template + ResultType get(); + + private: + + }; + +} // namespace concurrent +} // namespace cppcore From cb0bac680cb62ac50e9cf8c3d123848c342f21df Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Wed, 19 Nov 2025 13:39:48 +0100 Subject: [PATCH 2/2] Update async.h --- include/cppcore/Concurrent/async.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/cppcore/Concurrent/async.h b/include/cppcore/Concurrent/async.h index 6c7212d..c7fd04a 100644 --- a/include/cppcore/Concurrent/async.h +++ b/include/cppcore/Concurrent/async.h @@ -1,3 +1,25 @@ +/*----------------------------------------------------------------------------------------------- +The MIT License (MIT) + +Copyright (c) 2014-2025 Kim Kulling + +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +-----------------------------------------------------------------------------------------------*/ #pragma once namespace cppcore {