X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/35f62d21aaa13145012189acb5a84e9011a172e5..e9f0018b823e34405847177b25a85d3facc30ae1:/src/smpi/smpi_c99.c diff --git a/src/smpi/smpi_c99.c b/src/smpi/smpi_c99.c index 9d65579b96..15e49df534 100644 --- a/src/smpi/smpi_c99.c +++ b/src/smpi/smpi_c99.c @@ -1,24 +1,33 @@ -/* Copyright (c) 2011. The SimGrid Team. +/* Copyright (c) 2011-2014. The SimGrid Team. * All rights reserved. */ /* 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. */ + * under the terms of the license (GNU LGPL) which comes with this package. */ -#include +#include #include "private.h" -static void smpi_free_static(int status, void* arg) { - free(arg); -} +typedef struct s_smpi_static { + void *ptr; + void_f_pvoid_t free_fn; +} s_smpi_static_t; + +static xbt_dynar_t registered_static_stack = NULL; -void smpi_register_static(void* arg) { +void smpi_register_static(void* arg, void_f_pvoid_t free_fn) +{ + s_smpi_static_t elm = { arg, free_fn }; + if (!registered_static_stack) + registered_static_stack = xbt_dynar_new(sizeof(s_smpi_static_t), NULL); + xbt_dynar_push_as(registered_static_stack, s_smpi_static_t, elm); +} -#ifndef APPLE -// FIXME -// On Apple this error occurs: -// Undefined symbols for architecture x86_64: -// "_on_exit", referenced from: -// _smpi_register_static in smpi_c99.c.o - on_exit(&smpi_free_static, arg); -#endif +void smpi_free_static(void) +{ + while (!xbt_dynar_is_empty(registered_static_stack)) { + s_smpi_static_t elm = + xbt_dynar_pop_as(registered_static_stack, s_smpi_static_t); + elm.free_fn(elm.ptr); + } + xbt_dynar_free(®istered_static_stack); }