Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Added macros definitions and runtime support for cocci-processed local static variables.
authorpini <pini@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 20 Jan 2011 14:18:36 +0000 (14:18 +0000)
committerpini <pini@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Thu, 20 Jan 2011 14:18:36 +0000 (14:18 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@9450 48e7efb5-ca39-0410-a469-dd3cf9ba447f

buildtools/Cmake/DefinePackages.cmake
include/smpi/smpi_cocci.h
src/smpi/private.h
src/smpi/smpi_c99.c [new file with mode: 0644]

index 6cf1e8b..8137ed6 100644 (file)
@@ -108,6 +108,7 @@ set(SMPI_SRC
        src/smpi/smpi_global.c
        src/smpi/smpi_mpi.c
        src/smpi/smpi_pmpi.c
        src/smpi/smpi_global.c
        src/smpi/smpi_mpi.c
        src/smpi/smpi_pmpi.c
+       src/smpi/smpi_c99.c
        src/smpi/smpi_f77.c
        src/smpi/smpi_comm.c
        src/smpi/smpi_group.c
        src/smpi/smpi_f77.c
        src/smpi/smpi_comm.c
        src/smpi/smpi_group.c
index 1cce1a6..bcd150d 100644 (file)
@@ -7,10 +7,12 @@
 #ifndef SMPI_COCCI_H
 #define SMPI_COCCI_H
 
 #ifndef SMPI_COCCI_H
 #define SMPI_COCCI_H
 
+#include <xbt/misc.h>
+
 /* Macros used by coccinelle-generated code */
 
 /* Macros used by coccinelle-generated code */
 
-#define SMPI_VARINIT_GLOBAL(name,type)                       \
-type *name = NULL;                                                        \
+#define SMPI_VARINIT_GLOBAL(name,type)                          \
+type *name = NULL;                                              \
 void __attribute__((weak,constructor)) __preinit_##name(void) { \
    if(!name)                                                    \
       name = (type*)malloc(smpi_global_size() * sizeof(type));  \
 void __attribute__((weak,constructor)) __preinit_##name(void) { \
    if(!name)                                                    \
       name = (type*)malloc(smpi_global_size() * sizeof(type));  \
@@ -20,8 +22,8 @@ void __attribute__((weak,destructor)) __postfini_##name(void) { \
    name = NULL;                                                 \
 }
 
    name = NULL;                                                 \
 }
 
-#define SMPI_VARINIT_GLOBAL_AND_SET(name,type,expr)          \
-type *name = NULL;                                                        \
+#define SMPI_VARINIT_GLOBAL_AND_SET(name,type,expr)             \
+type *name = NULL;                                              \
 void __attribute__((weak,constructor)) __preinit_##name(void) { \
    size_t size = smpi_global_size();                            \
    size_t i;                                                    \
 void __attribute__((weak,constructor)) __preinit_##name(void) { \
    size_t size = smpi_global_size();                            \
    size_t i;                                                    \
@@ -40,4 +42,30 @@ void __attribute__((weak,destructor)) __postfini_##name(void) { \
 
 #define SMPI_VARGET_GLOBAL(name) name[smpi_process_index()]
 
 
 #define SMPI_VARGET_GLOBAL(name) name[smpi_process_index()]
 
+/* The following handle local static variables */
+
+XBT_PUBLIC(void) smpi_register_static(void* arg);
+
+#define SMPI_VARINIT_STATIC(name,type)                      \
+static type *name = NULL;                                   \
+if(!name) {                                                 \
+   name = (type*)malloc(smpi_global_size() * sizeof(type)); \
+   smpi_register_static(name);                              \
+}
+
+#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);                      \
+}
+
+#define SMPI_VARGET_STATIC(name) name[smpi_process_index()]
+
 #endif
 #endif
index 65f4839..12bf309 100644 (file)
@@ -12,6 +12,7 @@
 #include "simix/simix.h"
 #include "smpi/smpi.h"
 #include "smpi/smpif.h"
 #include "simix/simix.h"
 #include "smpi/smpi.h"
 #include "smpi/smpif.h"
+#include "smpi/smpi_cocci.h"
 #include "instr/instr_private.h"
 
 struct s_smpi_process_data;
 #include "instr/instr_private.h"
 
 struct s_smpi_process_data;
diff --git a/src/smpi/smpi_c99.c b/src/smpi/smpi_c99.c
new file mode 100644 (file)
index 0000000..2efa529
--- /dev/null
@@ -0,0 +1,16 @@
+/* Copyright (c) 2011. 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. */
+
+#include <stdlib.h>
+#include "private.h"
+
+static void smpi_free_static(int status, void* arg) {
+   free(arg);
+}
+
+void smpi_register_static(void* arg) {
+   on_exit(&smpi_free_static, arg);
+}