Skip to content
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

Initial and final function stacks: Use std::function #4218

Merged
merged 1 commit into from
Nov 6, 2024
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
4 changes: 2 additions & 2 deletions Src/Base/AMReX.H
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ namespace amrex
* classes to clean up any "global" state that they maintain when we're
* exiting from AMReX.
*/
void ExecOnFinalize (PTR_TO_VOID_FUNC);
void ExecOnInitialize (PTR_TO_VOID_FUNC);
void ExecOnFinalize (std::function<void()>);
void ExecOnInitialize (std::function<void()>);

//! This shuts up the compiler about unused variables
template <class... Ts>
Expand Down
16 changes: 8 additions & 8 deletions Src/Base/AMReX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,20 +302,20 @@ amrex::Assert_host (const char* EX, const char* file, int line, const char* msg)

namespace
{
std::stack<amrex::PTR_TO_VOID_FUNC> The_Finalize_Function_Stack;
std::stack<amrex::PTR_TO_VOID_FUNC> The_Initialize_Function_Stack;
std::stack<std::function<void()>> The_Finalize_Function_Stack;
std::stack<std::function<void()>> The_Initialize_Function_Stack;
}

void
amrex::ExecOnFinalize (PTR_TO_VOID_FUNC fp)
amrex::ExecOnFinalize (std::function<void()> f)
{
The_Finalize_Function_Stack.push(fp);
The_Finalize_Function_Stack.push(std::move(f));
}

void
amrex::ExecOnInitialize (PTR_TO_VOID_FUNC fp)
amrex::ExecOnInitialize (std::function<void()> f)
{
The_Initialize_Function_Stack.push(fp);
The_Initialize_Function_Stack.push(std::move(f));
}

amrex::AMReX*
Expand Down Expand Up @@ -391,7 +391,7 @@ amrex::Initialize (int& argc, char**& argv, bool build_parm_parse,
//
// Call the registered function.
//
(*The_Initialize_Function_Stack.top())();
The_Initialize_Function_Stack.top()();
//
// And then remove it from the stack.
//
Expand Down Expand Up @@ -756,7 +756,7 @@ amrex::Finalize (amrex::AMReX* pamrex)
//
// Call the registered function.
//
(*The_Finalize_Function_Stack.top())();
The_Finalize_Function_Stack.top()();
//
// And then remove it from the stack.
//
Expand Down
Loading