-
Notifications
You must be signed in to change notification settings - Fork 13
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
Resolving static lifetime problems #674
Merged
Merged
Changes from all commits
Commits
Show all changes
105 commits
Select commit
Hold shift + click to select a range
6625cc2
Remove the unused (and thread unsafe) timer classes.
timspainNERSC 78756b1
Remove timer classes. (#673)
timspainNERSC 9ee9e8b
Remove the static implementaion of NullIterator.
timspainNERSC 7914621
Remove the static implementaion of NullIterator. (#675)
timspainNERSC 415f648
clang formatting
timspainNERSC 510c326
clang formatting (#676)
timspainNERSC 0cc5791
Replace static non-const MissingData with a singleton double.
timspainNERSC 85584b3
Remove MissingData.cpp.
timspainNERSC e88205f
Use the default value.
timspainNERSC 8e1f627
Change the MissingData return types.
timspainNERSC a0beac8
clang formatting
timspainNERSC 44d49f3
Lazily initialize the file maps for ParaGridIO.
timspainNERSC 09a4026
Combine the two filename based maps to ensure consistency.
timspainNERSC 6a239f0
Add a finalizer class to mimic std::atexit, but with more control.
timspainNERSC ebfe38e
Better defined exception handling.
timspainNERSC d6c126e
clang formatting
timspainNERSC cbbdbe4
Merge branch 'issue683_finalizer' into issue614_ParaGridIO
timspainNERSC 721e4bf
Use the finalizer in place of std::atexit.
timspainNERSC 18a8aac
Make the final static maps const. Do things once for real.
timspainNERSC 72d051c
Change the static constants to an enum.
timspainNERSC 59945de
Change ConfigMap static constants to an enum. (#686)
timspainNERSC 75e13d2
clang formatting (or not)
timspainNERSC 0b64d04
Remove the static list.
timspainNERSC b0f9a68
Remove the FileCallbackCloser static list. (#687)
timspainNERSC 9e0f587
Move ConfigOutput to a local config key map.
timspainNERSC 557ca1d
Move ConfiguredAtmosphere to a local config key map.
timspainNERSC eb283e0
Move Model to a local config key map.
timspainNERSC d31c48b
Move all other classes to a local config key map.
timspainNERSC 6677a97
Rename localKeyMap to keyMap. Fix the Configurator test.
timspainNERSC eddafe1
Localize Configured keyMaps (#691)
timspainNERSC 91ebbdd
Issue614 missing data (#677)
timspainNERSC c988170
clang formatting
timspainNERSC 8f438b0
Move Xios to a local config key map.
timspainNERSC 6618588
clang formatting
timspainNERSC 73a8359
Remove static data from Configurator.
timspainNERSC 8a22ec7
Remove static data from Configurator. (#696)
timspainNERSC a854ea4
Indirectly reference the static implementation.
timspainNERSC ac52bca
Move Module<>::functionMap to be lazily initialized.
timspainNERSC c69b418
Move and rename the Module<> generationFunction.
timspainNERSC 1f89813
Move staticInstance to be lazily constructed, but keep the old code.
timspainNERSC 472d1f3
Simplify the Finalizer class.
timspainNERSC 64c4525
Use function pointers, rather than heavy std::function objects.
timspainNERSC b438e87
Move the Finalizer functions to a cpp source file.
timspainNERSC 4beab2e
clang formatting
timspainNERSC 172e1a4
Clean up Finalizer.hpp
timspainNERSC 6afdff6
Configure Modules at first request for an instance.
timspainNERSC 53297c2
Get the configured Module implementations at acquisition.
timspainNERSC 61753a7
Remove remaining references to parseConfigurator().
timspainNERSC f4e1ade
Remove redundant test classes.
timspainNERSC a5dc7fb
Remove the internal templates from the modules.
timspainNERSC 6d33a6f
Don't use the Configurator to select implementations in tests.
timspainNERSC 46a3e58
Debugging PrognosticData test.
timspainNERSC 6fcc642
Tidy up Module.hpp.
timspainNERSC 209e8e9
Remove the *Module.hpp files.
timspainNERSC 32d98ed
Remove the module header python script.
timspainNERSC 6692ad3
Prevent recursive initialization.
timspainNERSC 8177b7c
Replace typedefs by using statements.
timspainNERSC 2761fa7
Move the namespace function definitions to the template class.
timspainNERSC 5c9f9d9
Make Module independent of Nextsim.
timspainNERSC 0a52914
Move to the NextsimModule header (does not compile!).
timspainNERSC 5e1f05b
Use NextsimModule for ConfiguredModule.
timspainNERSC 4b936be
Revert to the Module name, remove template arguments.
timspainNERSC 3efb2e2
Correct function visibility in Module<>.
timspainNERSC ae11bfa
Remove debugging statements.
timspainNERSC cacde72
clang formatting
timspainNERSC c0c1ee5
Change the implmentation name internals to avoid stale names. Test.
timspainNERSC ffcdc30
Namespace the implementation name strings.
timspainNERSC 3207b58
Add getGenerationFunction to the template. Add fn for the default name.
timspainNERSC 6f337e8
clang formatting
timspainNERSC 07fb0b1
Add comments to the Module header.
timspainNERSC 4c792b5
Don't throw from Module<>::implementation.
timspainNERSC 8405eae
Suppress default initialization of a module (optionally).
timspainNERSC 954d846
clang formatting
timspainNERSC b505d7d
Add a finalizer method to the Module template class.
timspainNERSC c0bc27c
Issue 614 Module & ConfiguredModule (#704)
timspainNERSC 374bd7a
Revert to function objects. Remove redundant copy when finalizing.
timspainNERSC 741e1d0
Merge branch 'issue683_finalizer' into issue614_datalifetimes
timspainNERSC 3cc3387
Make sure to pop the throwing function.
timspainNERSC da9b9c2
Merge branch 'issue683_finalizer' into issue614_Modulefinalizer
timspainNERSC dfae6b0
Add module finalizers wherever modules are configured.
timspainNERSC 8913b82
Fix the uniqueness detection in the finalizer.
timspainNERSC 402fc9c
Use the finalizer after the iteration class returns.
timspainNERSC b0c4d35
Fix the uniqueness detection in the finalizer.
timspainNERSC e03f8d5
Merge branch 'issue683_finalizer' into issue614_datalifetimes
timspainNERSC 152de35
Fix the uniqueness detection in the finalizer even further.
timspainNERSC 9a95b9f
Fix the uniqueness detection in the finalizer even further.
timspainNERSC 3aa8037
Module & Finalizer: the module finalizer (#709)
timspainNERSC 9090eee
clang formatting (Model.cpp)
timspainNERSC c097f3e
Merge branch 'issue614_datalifetimes' into issue614_ParaGridIO
timspainNERSC ad65ea0
Issue 614 ParaGridIO (#685)
timspainNERSC 8a05004
clang formatting
timspainNERSC 3261ccf
Update the Finalizer API.
timspainNERSC 0c84cb1
Use using statements.
timspainNERSC d647161
clang formatting
timspainNERSC 620c0e1
Merge remote-tracking branch 'origin/develop' into
timspainNERSC b553059
Remove std::moves when passing around the implementation pointer.
timspainNERSC 9140a77
CamelCase the Module<> convenience type names.
timspainNERSC d77ca1e
std::unique_ptr can be cast directly to a bool with the same result.
timspainNERSC a772faa
Use a reference, rather than a pointer. Delete NullIterant.
timspainNERSC db73a2b
clang formatting that I should have remembered.
timspainNERSC e478c85
Tidy up the Finalizer test.
timspainNERSC 81fa973
Move the intialization outside the #ifdef block.
timspainNERSC 1966366
Change the ConfiguredModule default string to "".
timspainNERSC ebfaf8c
Compress the doOnce functionality of ParaGridIO.
timspainNERSC 04c6031
clang formatting
timspainNERSC File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/*! | ||
* @file Finalizer.cpp | ||
* | ||
* @date Sep 11, 2024 | ||
* @author Tim Spain <[email protected]> | ||
*/ | ||
|
||
#include "include/Finalizer.hpp" | ||
|
||
namespace Nextsim { | ||
|
||
void Finalizer::registerFunc(const FinalFn& fn) | ||
{ | ||
auto& fns = functions(); | ||
fns.push_back(fn); | ||
} | ||
|
||
bool Finalizer::registerUnique(const FinalFn& fn) | ||
{ | ||
if (contains(fn)) | ||
return false; | ||
registerFunc(fn); | ||
return true; | ||
} | ||
|
||
bool Finalizer::contains(const FinalFn& fn) | ||
{ | ||
auto& fns = functions(); | ||
for (const auto& stored : fns) { | ||
// Compare function addresses | ||
if (*stored.target<FnType*>() == *fn.target<FnType*>()) | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
void Finalizer::finalize() | ||
{ | ||
while (!functions().empty()) { | ||
try { | ||
// Execute the last function in the list | ||
functions().back()(); | ||
} catch (const std::exception& e) { | ||
// Remove the function from the finalization list even if an exception was thrown. | ||
functions().pop_back(); | ||
throw; | ||
} | ||
// Remove the function from the finalization list. | ||
functions().pop_back(); | ||
} | ||
} | ||
|
||
size_t Finalizer::count() { return functions().size(); } | ||
|
||
Finalizer::FinalFnContainer& Finalizer::functions() | ||
{ | ||
static FinalFnContainer set; | ||
return set; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
is there a reason this function returns a
bool
. Looks like it is mostly used like avoid
function.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.
The return value indicates whether the function was successfully registered (
true
) or not (false
). I this is useful enough functionality, given the minimal cost. Even if it is not currently used.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 guess my concern was, if you thought you were using it but you were not. Or if it was left in for some use case that we no longer need.
Do you think it would be more useful to raise an exception if the user tries to register an already registered function? Given the use in the rest of the code, my concern is that new developers are not likely to test the boolean return value.
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.
It's there as a service if the developer wants to know if the function was already registered. How it is used currently, I don't care, so I don't check. If a future developer does care, then they can check.