Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Avoid segfault or infinite loop when calling this function from somewhere else than...
[simgrid.git] / src / gras / gras.c
1 /* $Id$ */
2
3 /* gras.c -- generic functions not fitting anywhere else                    */
4
5 /* Copyright (c) 2003, 2004 Martin Quinson.                                 */
6 /* All rights reserved.                                                     */
7
8 /* This program is free software; you can redistribute it and/or modify it
9  * under the terms of the license (GNU LGPL) which comes with this package. */
10
11 #include "xbt/log.h"
12 #include "xbt/module.h" /* xbt_init/exit */
13
14 #include "gras_modinter.h"   /* module init/exit */
15 #include "xbt_modinter.h"   /* module init/exit */
16
17 #include "gras/core.h"
18 #include "gras/cond.h"    /* gras_if_RL() => FIXME: killme when gras/sg works */
19 #include "gras/process.h" /* FIXME: killme and put process_init in modinter */
20 #include "gras/chrono.h"
21
22 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(gras,XBT_LOG_ROOT_CAT,"All GRAS categories (cf. section \ref GRAS_API)");
23 static int gras_running_process = 0;
24
25 void gras_init(int *argc,char **argv, const char *defaultlog) {
26
27   INFO0("Initialize GRAS");
28   
29   /* First initialize the XBT */
30   xbt_init_defaultlog(argc,argv,defaultlog);
31    
32   gras_chrono_init();
33   /* module registrations: 
34    *    - declare process specific data we need (without creating them) 
35    */
36   if (gras_running_process == 0) {
37      gras_trp_register();
38      gras_msg_register();
39   }
40    
41   /*
42    * Initialize the process specific stuff
43    */
44   gras_process_init(); /* calls procdata_init, which creates process specific data for each module */
45   
46   /*
47    * Initialize the global stuff if it's not the first process created
48    */
49   if (gras_running_process++ == 0) {
50     gras_msg_init();
51     gras_trp_init();
52     gras_datadesc_init();
53   }
54 }
55
56 void gras_exit(void) {
57   INFO0("Exiting GRAS");
58   gras_process_exit();
59   if (--gras_running_process == 0) {
60     gras_msg_exit();
61     gras_trp_exit();
62     gras_datadesc_exit();
63   }
64   xbt_exit();
65 }