Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Hello xbt/synchro module (synchronization working both in simulation and real life...
[simgrid.git] / src / xbt / xbt_sg_synchro.c
1 /* $Id$ */
2
3 /* xbt_synchro -- Synchronization virtualized depending on whether we are   */
4 /*                in simulation or real life (act on simulated processes)   */
5
6 /* This is the simulation implementation, using simix.                      */
7
8 /* Copyright 2006,2007 Malek Cherier, Martin Quinson          
9  * All right reserved.                                                      */
10
11 /* This program is free software; you can redistribute it and/or modify it
12  * under the terms of the license (GNU LGPL) which comes with this package. */
13
14 #include "xbt/ex.h"
15
16 #include "xbt/synchro.h"     /* This module */
17
18 #include "simix/simix.h"     /* used implementation */
19 #include "simix/datatypes.h"
20
21 /* the implementation would be cleaner (and faster) with ELF symbol aliasing */
22
23 typedef struct s_xbt_thread_ {
24    /* KEEP IT IN SYNC WITH s_smx_process_ from src/include/simix/datatypes.h */
25    char *name;                  /**< @brief process name if any */
26    smx_simdata_process_t simdata;       /**< @brief simulator data */
27    s_xbt_swag_hookup_t process_hookup;
28    s_xbt_swag_hookup_t synchro_hookup;
29    s_xbt_swag_hookup_t host_proc_hookup;
30    void *data;                  /**< @brief user data */
31    /* KEEP IT IN SYNC WITH s_smx_process_ from src/include/simix/datatypes.h */
32 } s_xbt_thread_t;
33
34 xbt_thread_t xbt_thread_create(pvoid_f_pvoid_t start_routine, void* param)  {
35    THROW_UNIMPLEMENTED; /* FIXME */
36 }
37
38 void 
39 xbt_thread_join(xbt_thread_t thread,void ** thread_return) {
40    THROW_UNIMPLEMENTED; /* FIXME */
41 }                      
42
43 void xbt_thread_exit(int *retval) {
44    THROW_UNIMPLEMENTED; /* FIXME */
45 }
46
47 xbt_thread_t xbt_thread_self(void) {
48    THROW_UNIMPLEMENTED; /* FIXME */   
49 }
50
51 void xbt_thread_yield(void) {
52    THROW_UNIMPLEMENTED; /* FIXME */   
53 }
54 /****** mutex related functions ******/
55 struct s_xbt_mutex_ {
56    
57    /* KEEP IT IN SYNC WITH src/simix/private.h::struct s_smx_mutex */
58    xbt_swag_t sleeping;                 /* list of sleeping process */
59    int using;
60    /* KEEP IT IN SYNC WITH src/simix/private.h::struct s_smx_mutex */
61    
62 };
63
64 xbt_mutex_t xbt_mutex_init(void) {
65    return (xbt_mutex_t)SIMIX_mutex_init();
66 }
67
68 void xbt_mutex_lock(xbt_mutex_t mutex) {
69    SIMIX_mutex_lock( (smx_mutex_t)mutex) ;
70 }
71
72 void xbt_mutex_unlock(xbt_mutex_t mutex) {
73    SIMIX_mutex_unlock( (smx_mutex_t)mutex );
74 }
75
76 void xbt_mutex_destroy(xbt_mutex_t mutex) {
77    SIMIX_mutex_destroy( (smx_mutex_t)mutex );
78 }
79
80 /***** condition related functions *****/
81 struct s_xbt_cond_ {
82    
83    /* KEEP IT IN SYNC WITH src/simix/private.h::struct s_smx_cond */
84    xbt_swag_t sleeping;                         /* list of sleeping process */
85    smx_mutex_t  mutex;
86    xbt_fifo_t actions;                  /* list of actions */
87    /* KEEP IT IN SYNC WITH src/simix/private.h::struct s_smx_cond */
88
89 };
90
91 xbt_cond_t xbt_cond_init(void) {
92    return (xbt_cond_t)SIMIX_cond_init();
93 }
94
95 void xbt_cond_wait(xbt_cond_t cond, xbt_mutex_t mutex) {
96    SIMIX_cond_wait( (smx_cond_t)cond , (smx_mutex_t)mutex );
97 }
98
99 void xbt_cond_signal(xbt_cond_t cond) {
100    SIMIX_cond_signal( (smx_cond_t)cond );
101 }
102          
103 void xbt_cond_broadcast(xbt_cond_t cond){
104    SIMIX_cond_broadcast( (smx_cond_t)cond );
105 }
106 void xbt_cond_destroy(xbt_cond_t cond){
107    SIMIX_cond_destroy( (smx_cond_t)cond );
108 }