Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Make room for the new xbt_thread module
[simgrid.git] / src / xbt / xbt_main.c
1 /* $Id$ */
2
3 /* module handling                                                          */
4
5 /* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved.            */
6
7 /* This program is free software; you can redistribute it and/or modify it
8  * under the terms of the license (GNU LGPL) which comes with this package. */
9
10 #include "time.h" /* to seed the random generator */
11
12 #include "xbt/sysdep.h"
13 #include "xbt/log.h"
14 #include "xbt/dynar.h"
15 #include "xbt/config.h"
16
17 #include "xbt/module.h" /* this module */
18
19 #include "xbt_modinter.h"  /* prototype of other module's init/exit in XBT */
20
21 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(module,xbt, "module handling");
22
23 char *xbt_binary_name=NULL; /* Mandatory to retrieve neat backtraces */
24 int xbt_initialized=0;
25
26 /** @brief Initialize the xbt mechanisms. */
27 void 
28 xbt_init(int *argc, char **argv) {
29   xbt_initialized++;
30
31   if (xbt_initialized!=1)
32     return;
33
34   xbt_binary_name = xbt_strdup(argv[0]);
35   srand((unsigned int)time(NULL));
36   VERB0("Initialize XBT");
37   
38   xbt_log_init(argc,argv);
39   xbt_thread_mod_init();
40 }
41
42 /** @brief Finalize the xbt mechanisms. */
43 void 
44 xbt_exit(){
45   xbt_initialized--;
46   if (xbt_initialized == 0) {
47     free(xbt_binary_name);
48     xbt_fifo_exit();
49     xbt_dict_exit();
50     xbt_thread_mod_exit();
51   }
52   xbt_log_exit();
53 }
54