Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
commiting some more automatic source patching stuff, and renamed some of the
[simgrid.git] / include / smpi / smpi_cocci.h
1 /* Copyright (c) 2011. 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 #ifndef SMPI_COCCI_H
8 #define SMPI_COCCI_H
9
10 /* Macros used by coccinelle-generated code */
11
12 #define SMPI_VARINIT_GLOBAL(name,type)                       \
13 type *name = NULL;                                                        \
14 void __attribute__((weak,constructor)) __preinit_##name(void) { \
15    if(!name)                                                    \
16       name = (type*)malloc(smpi_global_size() * sizeof(type));  \
17 }                                                               \
18 void __attribute__((weak,destructor)) __postfini_##name(void) { \
19    free(name);                                                  \
20    name = NULL;                                                 \
21 }
22
23 #define SMPI_VARINIT_GLOBAL_AND_SET(name,type,expr)          \
24 type *name = NULL;                                                        \
25 void __attribute__((weak,constructor)) __preinit_##name(void) { \
26    size_t size = smpi_global_size();                            \
27    size_t i;                                                    \
28    type value = expr;                                           \
29    if(!name) {                                                  \
30       name = (type*)malloc(size * sizeof(type));                \
31       for(i = 0; i < size; i++) {                               \
32          name[i] = value;                                       \
33       }                                                         \
34    }                                                            \
35 }                                                               \
36 void __attribute__((weak,destructor)) __postfini_##name(void) { \
37    free(name);                                                  \
38    name = NULL;                                                 \
39 }
40
41 #define SMPI_VARGET_GLOBAL(name) name[smpi_process_index()]
42
43 #endif