-
Notifications
You must be signed in to change notification settings - Fork 10
fix #514, call_data_callbacks after shared the data #548
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?
Changes from all commits
b136fcf
352441e
668bccb
2b5e3bb
0d1998d
4805e94
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 | ||||
|---|---|---|---|---|---|---|
| @@ -1,5 +1,5 @@ | ||||||
| /******************************************************************************* | ||||||
| * Copyright (C) 2015-2024 Commissariat a l'energie atomique et aux energies alternatives (CEA) | ||||||
| * Copyright (C) 2015-2026 Commissariat a l'energie atomique et aux energies alternatives (CEA) | ||||||
| * All rights reserved. | ||||||
| * | ||||||
| * Redistribution and use in source and binary forms, with or without | ||||||
|
|
@@ -30,9 +30,14 @@ | |||||
| #include <paraconf.h> | ||||||
|
|
||||||
| #include <pdi/pdi_fwd.h> | ||||||
| #include <pdi/callbacks.h> | ||||||
| #include <pdi/context.h> | ||||||
| #include <pdi/data_descriptor.h> | ||||||
| #include <pdi/datatype_template.h> | ||||||
| #include <pdi/ref_any.h> | ||||||
|
|
||||||
| // #include "global_context.h" | ||||||
|
|
||||||
|
Comment on lines
+39
to
+40
Member
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.
Suggested change
|
||||||
| namespace PDI { | ||||||
|
|
||||||
| class PDI_EXPORT Data_descriptor | ||||||
|
|
@@ -85,6 +90,14 @@ class PDI_EXPORT Data_descriptor | |||||
| */ | ||||||
| virtual void share(void* data, bool read, bool write) = 0; | ||||||
|
|
||||||
| /** Shares some data with PDI | ||||||
| * \param[in,out] data the shared data | ||||||
| * \param read whether read access is granted to other references | ||||||
| * \param write whether write access is granted to other references | ||||||
| * \param delayed_callbacks a class that allow to delay trigger_delayed_data_callbacks for a list of a data | ||||||
|
Member
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.
Suggested change
|
||||||
| */ | ||||||
| virtual void share(void* data, bool read, bool write, Delayed_data_callbacks&& delayed_callbacks) = 0; | ||||||
|
|
||||||
| /** Shares some data with PDI | ||||||
| * \param[in,out] ref a reference to the shared data | ||||||
| * \param read whether the stored reference should have read access | ||||||
|
|
@@ -93,6 +106,19 @@ class PDI_EXPORT Data_descriptor | |||||
| */ | ||||||
| virtual void* share(Ref ref, bool read, bool write) = 0; | ||||||
|
|
||||||
| /** Shares some data with PDI | ||||||
| * \param[in,out] ref a reference to the shared data | ||||||
| * \param read whether the stored reference should have read access | ||||||
| * \param write whether the stored reference should have write access | ||||||
| * \param delayed_callbacks a class that allow to delay trigger_delayed_data_callbacks for a list of a data | ||||||
|
Member
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.
Suggested change
|
||||||
| * \return the just shared buffer | ||||||
| */ | ||||||
| virtual void* share(Ref ref, bool read, bool write, Delayed_data_callbacks&& delayed_callbacks) = 0; | ||||||
|
|
||||||
| /** function to call "data_callbacks" for the shared data. | ||||||
| */ | ||||||
| virtual void trigger_delayed_data_callbacks() = 0; | ||||||
|
Member
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. Why is it still required?
Contributor
Author
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. We need that because Do you want to remove trigger_delayed_data_callbacks() in the class I want to keep this function inside /// References to the values of this descriptor
std::stack<std::unique_ptr<Ref_holder>> m_refs; |
||||||
|
|
||||||
| /** Releases ownership of a data shared with PDI. PDI is then responsible to | ||||||
| * free the associated memory whenever necessary. | ||||||
| */ | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,128 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /******************************************************************************* | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Copyright (C) 2026 Commissariat a l'energie atomique et aux energies alternatives (CEA) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * All rights reserved. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * Redistribution and use in source and binary forms, with or without | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * modification, are permitted provided that the following conditions are met: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * * Redistributions of source code must retain the above copyright | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * notice, this list of conditions and the following disclaimer. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * * Redistributions in binary form must reproduce the above copyright | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * notice, this list of conditions and the following disclaimer in the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * documentation and/or other materials provided with the distribution. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * * Neither the name of CEA nor the names of its contributors may be used to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * endorse or promote products derived from this software without specific | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * prior written permission. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| * 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. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ******************************************************************************/ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #ifndef PDI_DELAYED_DATA_CALLBACK_H_ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #define PDI_DELAYED_DATA_CALLBACK_H_ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <string> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <vector> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <pdi/pdi_fwd.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "pdi/context.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "pdi/datatype.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "pdi/error.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "pdi/plugin.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "pdi/ref_any.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "pdi/scalar_datatype.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <pdi/context.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <pdi/data_descriptor.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <pdi/datatype_template.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <pdi/ref_any.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include <data_descriptor_impl.h> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #include "global_context.h" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| namespace PDI { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| class PDI_EXPORT Delayed_data_callbacks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// friend class Global_context; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
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. What does this comment mean? |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| std::vector<std::string> m_datanames; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// The context this descriptor is part of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
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. This is not a descriptor, is it? |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Global_context& m_context; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| public: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// constructor used in: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// - the case of PDI_multi_expose | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// - when a user want to define is own "Delayed_data_callbacks" object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
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.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| /// Remark: This constructor doesn't work if PDI_init is not called. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
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.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Delayed_data_callbacks(Global_context& ctx) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : m_datanames{} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| , m_context{ctx} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| {} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // In the destructor, we need to throw an error message in case of the callback on the data doesn't work (trigger function) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // (example: error in the config.yml for a plugin, error due to external library incompatibility) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ~Delayed_data_callbacks() noexcept(false) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Yushan-Wang marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
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. why not move the try one step up? |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this->trigger(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (Error& e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (std::uncaught_exceptions()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
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. I'm not sure that this is useful. I would not use
Contributor
Author
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. The paper in reference talk about If we have a |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // An exception is throwing. Print simple message to avoid std::terminate. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| m_context.logger().error("Error in the destructor of Delayed_data_callbacks, {}", e.what()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // No exception is throwing. Throw an error. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw Error(e.status(), "Error in the destructor of Delayed_data_callbacks, {}", e.what()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Yushan-Wang marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (const std::exception& e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (std::uncaught_exceptions()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
jmorice91 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // An exception is throwing. Print simple message to avoid std::terminate. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| m_context.logger().error("Error in the destructor of Delayed_data_callbacks, {}", e.what()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // No exception is throwing. Throw an error. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| m_context.logger().error("Error in the destructor of Delayed_data_callbacks."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
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. since you rethrow. I wouldn't print anything in that case:
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
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. you should not throw in a noexcept method.
Contributor
Author
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. In this choice of implementation, the destructor may throw. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (...) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (std::uncaught_exceptions()) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
jmorice91 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // An exception is throwing. Print simple message to avoid std::terminate. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| m_context.logger().error("Error in the destructor of Delayed_data_callbacks."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // No exception is throwing. Throw an error. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| m_context.logger().error("Error in the destructor of Delayed_data_callbacks."); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Member
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. same as above
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
jmorice91 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // add element to the list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void add_dataname(const std::string& name) { m_datanames.emplace_back(name); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // trigger_delayed_data_callbacks() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void trigger() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| int i = 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| size_t number_of_elements = m_datanames.size(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for (auto&& element_name: m_datanames) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| m_context.logger().trace("Trigger data callback `{}' ({}/{})", element_name.c_str(), ++i, number_of_elements); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| m_context[element_name.c_str()].trigger_delayed_data_callbacks(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this->cancel(); // clear the m_datanames | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (Error& e) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this->cancel(); // clear the m_datanames | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw Error(e.status(), "Error in trigger data callback: `{}'", e.what()); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (...) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| this->cancel(); // clear the m_datanames | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| throw; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+106
to
+121
Member
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. When an exception is thrown, we'd like the events not yet triggered to remain in the list of events to trigger.
Suggested change
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // clear the element in the list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| void cancel() { m_datanames.clear(); } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; // class Delayed_data_callbacks | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } // namespace PDI | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #endif // PDI_DELAYED_DATA_CALLBACK_H_ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
remove?
Uh oh!
There was an error while loading. Please reload this page.
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.
I will be remove in the next commit