Logo AND Algorithmique Numérique Distribuée

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