Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New thread to receive messages. Not working yet.
[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          res->msg_received = xbt_queue_new(0,sizeof(s_gras_msg_t));
34    
35    return (void*)res;
36 }
37
38 /*
39  * Freeing procdata for this module
40  */
41 static void gras_msg_procdata_free(void *data) {
42    gras_msg_procdata_t res = (gras_msg_procdata_t)data;
43    
44    xbt_dynar_free(&( res->msg_queue ));
45    xbt_dynar_free(&( res->msg_waitqueue ));
46    xbt_dynar_free(&( res->cbl_list ));
47    xbt_dynar_free(&( res->timers ));
48    xbt_fifo_free( res->msg_to_receive_queue );
49    xbt_fifo_free( res->msg_to_receive_queue_meas );
50
51    free(res->name);
52    free(res);
53 }
54
55 /*
56  * Module registration
57  */
58 int gras_msg_libdata_id;
59 void gras_msg_register() {
60    gras_msg_libdata_id = gras_procdata_add("gras_msg",gras_msg_procdata_new, gras_msg_procdata_free);
61 }
62
63 /*
64  * Initialize this submodule.
65  */
66 void gras_msg_init(void) {
67   /* only initialize once */
68   if (_gras_msgtype_set != NULL)
69     return;
70
71   VERB0("Initializing Msg");
72   
73   _gras_msgtype_set = xbt_set_new();
74
75   memcpy(_GRAS_header,"GRAS", 4);
76   _GRAS_header[4]=GRAS_PROTOCOL_VERSION;
77   _GRAS_header[5]=(char)GRAS_THISARCH;
78    
79   gras_msg_ctx_mallocator = 
80      xbt_mallocator_new(1000,
81                         gras_msg_ctx_mallocator_new_f,
82                         gras_msg_ctx_mallocator_free_f,
83                         gras_msg_ctx_mallocator_reset_f);
84 }
85
86 /*
87  * Finalize the msg module
88  */
89 void
90 gras_msg_exit(void) {
91   VERB0("Exiting Msg");
92   xbt_set_free(&_gras_msgtype_set);
93
94   xbt_mallocator_free(gras_msg_ctx_mallocator);
95 }
96