Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'mc' into mc++
[simgrid.git] / src / simix / smx_synchro_private.h
1 /* Copyright (c) 2012, 2014. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #ifndef _SIMIX_SYNCHRO_PRIVATE_H
8 #define _SIMIX_SYNCHRO_PRIVATE_H
9
10 #include "xbt/swag.h"
11 #include "xbt/xbt_os_thread.h"
12
13 typedef struct s_smx_mutex {
14   unsigned int locked;
15   smx_process_t owner;
16   xbt_swag_t sleeping;          /* list of sleeping process */
17 } s_smx_mutex_t;
18
19 typedef struct s_smx_cond {
20   smx_mutex_t mutex;
21   xbt_swag_t sleeping;          /* list of sleeping process */
22 } s_smx_cond_t;
23
24 typedef struct s_smx_sem {
25   unsigned int value;
26   xbt_swag_t sleeping;          /* list of sleeping process */
27 } s_smx_sem_t;
28
29 void SIMIX_post_synchro(smx_action_t action);
30 void SIMIX_synchro_stop_waiting(smx_process_t process, smx_simcall_t simcall);
31 void SIMIX_synchro_destroy(smx_action_t action);
32
33 smx_mutex_t SIMIX_mutex_init(void);
34 void SIMIX_mutex_destroy(smx_mutex_t mutex);
35 void SIMIX_pre_mutex_lock(smx_simcall_t simcall, smx_mutex_t mutex);
36 int SIMIX_mutex_trylock(smx_mutex_t mutex, smx_process_t issuer);
37 void SIMIX_mutex_unlock(smx_mutex_t mutex, smx_process_t issuer);
38
39 smx_cond_t SIMIX_cond_init(void);
40 void SIMIX_cond_destroy(smx_cond_t cond);
41 void SIMIX_cond_signal(smx_cond_t cond);
42 void SIMIX_pre_cond_wait(smx_simcall_t simcall, smx_cond_t cond, smx_mutex_t mutex);
43 void SIMIX_pre_cond_wait_timeout(smx_simcall_t simcall, smx_cond_t cond,
44                                  smx_mutex_t mutex, double timeout);
45 void SIMIX_cond_broadcast(smx_cond_t cond);
46
47 smx_sem_t SIMIX_sem_init(unsigned int value);
48 void SIMIX_sem_destroy(smx_sem_t sem);
49 void SIMIX_sem_release(smx_sem_t sem);
50 int SIMIX_sem_would_block(smx_sem_t sem);
51 void SIMIX_pre_sem_acquire(smx_simcall_t simcall, smx_sem_t sem);
52 void SIMIX_pre_sem_acquire_timeout(smx_simcall_t simcall, smx_sem_t sem, double timeout);
53 int SIMIX_sem_get_capacity(smx_sem_t sem);
54
55 // pre prototypes
56 smx_mutex_t SIMIX_pre_mutex_init(smx_simcall_t simcall);
57 void SIMIX_pre_mutex_destroy(smx_simcall_t simcall, smx_mutex_t mutex);
58 int SIMIX_pre_mutex_trylock(smx_simcall_t simcall, smx_mutex_t mutex);
59 void SIMIX_pre_mutex_unlock(smx_simcall_t simcall, smx_mutex_t mutex);
60 smx_cond_t SIMIX_pre_cond_init(smx_simcall_t simcall);
61 void SIMIX_pre_cond_destroy(smx_simcall_t simcall, smx_cond_t cond);
62 void SIMIX_pre_cond_signal(smx_simcall_t simcall, smx_cond_t cond);
63 void SIMIX_pre_cond_broadcast(smx_simcall_t simcall, smx_cond_t cond);
64 smx_sem_t SIMIX_pre_sem_init(smx_simcall_t simcall, unsigned int value);
65 void SIMIX_pre_sem_destroy(smx_simcall_t simcall, smx_sem_t sem);
66 void SIMIX_pre_sem_release(smx_simcall_t simcall, smx_sem_t sem);
67 static XBT_INLINE int SIMIX_pre_sem_would_block(smx_simcall_t simcall,
68                                                 smx_sem_t sem)
69 {
70   return SIMIX_sem_would_block(sem);
71 }
72 int SIMIX_pre_sem_get_capacity(smx_simcall_t simcall, smx_sem_t sem);
73 #endif