Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[SMPI] Convert smpi_c99.cpp to actual C++ code
authorChristian Heinrich <franz-christian.heinrich@inria.fr>
Sat, 4 Jun 2016 14:42:25 +0000 (16:42 +0200)
committerChristian Heinrich <franz-christian.heinrich@inria.fr>
Wed, 8 Jun 2016 13:47:20 +0000 (15:47 +0200)
src/smpi/smpi_c99.cpp

index 689ac88..cd0dff3 100644 (file)
@@ -4,7 +4,7 @@
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
-#include <xbt/dynar.h>
+#include <stack>
 #include "private.h"
 
 typedef struct s_smpi_static {
@@ -12,22 +12,22 @@ typedef struct s_smpi_static {
   void_f_pvoid_t free_fn;
 } s_smpi_static_t;
 
-static xbt_dynar_t registered_static_stack = NULL;
+/**
+ * \brief Holds a reference to all static variables that were registered
+ *        via smpi_register_static(). This helps to free them when
+ *        SMPI shuts down.
+ */
+static std::stack<s_smpi_static_t> registered_static_variables_stack;
 
-void smpi_register_static(void* arg, void_f_pvoid_t free_fn)
-{
-  s_smpi_static_t elm = { arg, free_fn };
-  if (registered_static_stack==NULL)
-    registered_static_stack = xbt_dynar_new(sizeof(s_smpi_static_t), NULL);
-  xbt_dynar_push_as(registered_static_stack, s_smpi_static_t, elm);
+void smpi_register_static(void* arg, void_f_pvoid_t free_fn) {
+  s_smpi_static_t elm { arg, free_fn };
+  registered_static_variables_stack.push(elm);
 }
 
-void smpi_free_static(void)
-{
-  while (xbt_dynar_is_empty(registered_static_stack)==0) {
-    s_smpi_static_t elm =
-      xbt_dynar_pop_as(registered_static_stack, s_smpi_static_t);
+void smpi_free_static(void) {
+  while (!registered_static_variables_stack.empty()) {
+    s_smpi_static_t elm = registered_static_variables_stack.top();
     elm.free_fn(elm.ptr);
+    registered_static_variables_stack.pop();
   }
-  xbt_dynar_free(&registered_static_stack);
 }