Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Split up a too long file, taking the oportunity to sanitize the file naming spacec
[simgrid.git] / src / gras / Msg / gras_msg_mod.c
1 /* $Id$ */
2
3 /* gras message types handling                                              */
4
5 /* Copyright (c) 2003, 2004, 2005, 2006, 2007 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/ex.h"
12 #include "gras/Msg/msg_private.h"
13 #include "gras/Virtu/virtu_interface.h"
14
15 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(gras_msg);
16
17 extern xbt_set_t _gras_msgtype_set;
18
19 /*
20  * Creating procdata for this module
21  */
22 static void *gras_msg_procdata_new() {
23    gras_msg_procdata_t res = xbt_new(s_gras_msg_procdata_t,1);
24    
25    res->name = xbt_strdup("gras_msg");
26    res->name_len = 0;
27    res->msg_queue     = xbt_dynar_new(sizeof(s_gras_msg_t),   NULL);
28    res->msg_waitqueue = xbt_dynar_new(sizeof(s_gras_msg_t),   NULL);
29    res->cbl_list      = xbt_dynar_new(sizeof(gras_cblist_t *),gras_cbl_free);
30    res->timers        = xbt_dynar_new(sizeof(s_gras_timer_t), NULL);
31    res->msg_to_receive_queue = xbt_fifo_new();
32    res->msg_to_receive_queue_meas = xbt_fifo_new();
33    
34    return (void*)res;
35 }
36
37 /*
38  * Freeing procdata for this module
39  */
40 static void gras_msg_procdata_free(void *data) {
41    gras_msg_procdata_t res = (gras_msg_procdata_t)data;
42    
43    xbt_dynar_free(&( res->msg_queue ));
44    xbt_dynar_free(&( res->msg_waitqueue ));
45    xbt_dynar_free(&( res->cbl_list ));
46    xbt_dynar_free(&( res->timers ));
47    xbt_fifo_free( res->msg_to_receive_queue );
48    xbt_fifo_free( res->msg_to_receive_queue_meas );
49
50    free(res->name);
51    free(res);
52 }
53
54 /*
55  * Module registration
56  */
57 int gras_msg_libdata_id;
58 void gras_msg_register() {
59    gras_msg_libdata_id = gras_procdata_add("gras_msg",gras_msg_procdata_new, gras_msg_procdata_free);
60 }
61
62 /*
63  * Initialize this submodule.
64  */
65 void gras_msg_init(void) {
66   /* only initialize once */
67   if (_gras_msgtype_set != NULL)
68     return;
69
70   VERB0("Initializing Msg");
71   
72   _gras_msgtype_set = xbt_set_new();
73
74   memcpy(_GRAS_header,"GRAS", 4);
75   _GRAS_header[4]=GRAS_PROTOCOL_VERSION;
76   _GRAS_header[5]=(char)GRAS_THISARCH;
77    
78   gras_msg_ctx_mallocator = 
79      xbt_mallocator_new(1000,
80                         gras_msg_ctx_mallocator_new_f,
81                         gras_msg_ctx_mallocator_free_f,
82                         gras_msg_ctx_mallocator_reset_f);
83 }
84
85 /*
86  * Finalize the msg module
87  */
88 void
89 gras_msg_exit(void) {
90   VERB0("Exiting Msg");
91   xbt_set_free(&_gras_msgtype_set);
92
93   xbt_mallocator_free(gras_msg_ctx_mallocator);
94 }
95