Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
change macro names to avoid nameclashes on FINISHED
[simgrid.git] / src / smpi / internals / smpi_static_variables.cpp
1 /* Copyright (c) 2011-2018. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include "private.hpp"
7 #include <stack>
8
9 struct s_smpi_static_t {
10   void *ptr;
11   void_f_pvoid_t free_fn;
12 };
13
14 /**
15  * \brief Holds a reference to all static variables that were registered
16  *        via smpi_register_static(). This helps to free them when
17  *        SMPI shuts down.
18  */
19 static std::stack<s_smpi_static_t> registered_static_variables_stack;
20
21 void smpi_register_static(void* arg, void_f_pvoid_t free_fn) {
22   s_smpi_static_t elm { arg, free_fn };
23   registered_static_variables_stack.push(elm);
24 }
25
26 void smpi_free_static() {
27   while (not registered_static_variables_stack.empty()) {
28     s_smpi_static_t elm = registered_static_variables_stack.top();
29     elm.free_fn(elm.ptr);
30     registered_static_variables_stack.pop();
31   }
32 }