-
Notifications
You must be signed in to change notification settings - Fork 4
First prototypes #46
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
First prototypes #46
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| /*----------------------------------------------------------------------------------------------- | ||
| 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 { | ||
| 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<typename Task> | ||
| 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<typename Func> | ||
| 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<typename ResultType> | ||
| ResultType get(); | ||
|
|
||
| private: | ||
|
|
||
| }; | ||
|
Comment on lines
+74
to
+104
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Finish
🤖 Prompt for AI Agents |
||
|
|
||
| } // namespace concurrent | ||
| } // namespace cppcore | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Provide concrete definitions for
Executor’s API.run(),isRunning(),submit(), andshutdown()are only declared here, and the PR does not supply definitions anywhere else. The first translation unit that calls any of them will fail to link with unresolved externals. Either supply working implementations in this PR (inline or in a new.cpp) or make the class an abstract interface with pure-virtual members until the executor exists. Right now the header exports a non-functional type.🤖 Prompt for AI Agents