X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/5c8ede40c4f5e920bd12b2e4ede74db2892e0d60..421c3ca52031a1c231fb91ec35dafa0e88050242:/include/smpi/smpi_cocci.h diff --git a/include/smpi/smpi_cocci.h b/include/smpi/smpi_cocci.h index 29daeec643..f938a9bdf2 100644 --- a/include/smpi/smpi_cocci.h +++ b/include/smpi/smpi_cocci.h @@ -1,4 +1,4 @@ -/* 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 @@ -7,22 +7,24 @@ #ifndef SMPI_COCCI_H #define SMPI_COCCI_H +#include + /* Macros used by coccinelle-generated code */ -#define SMPI_INITIALIZE_GLOBAL(name,type) \ - NULL; \ -void __attribute__((weak,constructor)) __preinit_##name(void) { \ +#define SMPI_VARINIT_GLOBAL(name,type) \ +type *name = NULL; \ +static void __attribute__((constructor)) __preinit_##name(void) { \ if(!name) \ - name = (type*)malloc(smpi_global_size() * sizeof(type)); \ + name = (type*)calloc(smpi_global_size(), sizeof(type)); \ } \ -void __attribute__((weak,destructor)) __postfini_##name(void) { \ +static void __attribute__((destructor)) __postfini_##name(void) { \ free(name); \ name = NULL; \ } -#define SMPI_INITIALIZE_AND_SET_GLOBAl(name,type,expr) \ - NULL; \ -void __attribute__((weak,constructor)) __preinit_##name(void) { \ +#define SMPI_VARINIT_GLOBAL_AND_SET(name,type,expr) \ +type *name = NULL; \ +static void __attribute__((constructor)) __preinit_##name(void) { \ size_t size = smpi_global_size(); \ size_t i; \ type value = expr; \ @@ -33,11 +35,43 @@ void __attribute__((weak,constructor)) __preinit_##name(void) { \ } \ } \ } \ -void __attribute__((weak,destructor)) __postfini_##name(void) { \ +static void __attribute__((destructor)) __postfini_##name(void) { \ free(name); \ name = NULL; \ } -#define SMPI_GLOBAL_VAR_LOCAL_ACCESS(name) name[smpi_process_index()] +#define SMPI_VARGET_GLOBAL(name) name[smpi_process_index()] + +/* The following handle local static variables */ +/** @brief Make sure that the passed pointer is freed on process exit. + * + * This function is rather internal, mainly used for the + * privatization of global variables through coccinelle. + */ +XBT_PUBLIC(void) smpi_register_static(void* arg, void_f_pvoid_t free_fn); + +XBT_PUBLIC(void) smpi_free_static(void); + +#define SMPI_VARINIT_STATIC(name,type) \ +static type *name = NULL; \ +if(!name) { \ + name = (type*)calloc(smpi_global_size(), sizeof(type)); \ + smpi_register_static(name, xbt_free_f); \ +} + +#define SMPI_VARINIT_STATIC_AND_SET(name,type,expr) \ +static type *name = NULL; \ +if(!name) { \ + size_t size = smpi_global_size(); \ + size_t i; \ + type value = expr; \ + name = (type*)malloc(size * sizeof(type)); \ + for(i = 0; i < size; i++) { \ + name[i] = value; \ + } \ + smpi_register_static(name, xbt_free_f); \ +} + +#define SMPI_VARGET_STATIC(name) name[smpi_process_index()] #endif