Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'models_type_rework_part2_try2' into 'master'
[simgrid.git] / include / xbt / synchro.h
1 /* xbt/synchro.h -- Simulated synchronization                               */
2
3 /* Copyright (c) 2009-2021. The SimGrid Team.                               */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 #ifndef XBT_SYNCHRO_H
9 #define XBT_SYNCHRO_H
10
11 #include "simgrid/cond.h"
12 #include "simgrid/mutex.h"
13 #include <xbt/misc.h> /* SG_BEGIN_DECL */
14
15 #warning xbt/synchro.h is deprecated and will be removed in v3.28.
16
17 SG_BEGIN_DECL
18
19 /** @addtogroup XBT_synchro
20  *  @brief XBT synchronization tools
21  *
22  *  This section describes the simulated synchronization mechanisms,
23  *  that you can use in your simulation without deadlocks. See @ref
24  *  faq_MIA_thread_synchronization for details.
25  *
26  *  @{
27  */
28
29 /** @brief Thread mutex data type (opaque object)
30  *  @hideinitializer
31  */
32 typedef sg_mutex_t xbt_mutex_t;
33
34 /** @brief Creates a new mutex variable */
35 XBT_ATTRIB_DEPRECATED_v328("Please use sg_mutex_init") static inline xbt_mutex_t xbt_mutex_init(void)
36 {
37   return sg_mutex_init();
38 }
39
40 /** @brief Blocks onto the given mutex variable */
41 XBT_ATTRIB_DEPRECATED_v328("Please use sg_mutex_lock") static inline void xbt_mutex_acquire(xbt_mutex_t mutex)
42 {
43   sg_mutex_lock(mutex);
44 }
45
46 /** @brief Tries to block onto the given mutex variable
47  * Tries to lock a mutex, return 1 if the mutex is unlocked, else 0.
48  * This function does not block and wait for the mutex to be unlocked.
49  * @param mutex The mutex
50  * @return 1 - mutex free, 0 - mutex used
51  */
52 XBT_ATTRIB_DEPRECATED_v328("Please use sg_mutex_try_lock") static inline int xbt_mutex_try_acquire(xbt_mutex_t mutex)
53 {
54   return sg_mutex_try_lock(mutex);
55 }
56
57 /** @brief Releases the given mutex variable */
58 XBT_ATTRIB_DEPRECATED_v328("Please use sg_mutex_unlock") static inline void xbt_mutex_release(xbt_mutex_t mutex)
59 {
60   sg_mutex_unlock(mutex);
61 }
62
63 /** @brief Destroys the given mutex variable */
64 XBT_ATTRIB_DEPRECATED_v328("Please use sg_mutex_destroy") static inline void xbt_mutex_destroy(xbt_mutex_t mutex)
65 {
66   sg_mutex_destroy(mutex);
67 }
68
69 /** @brief Thread condition data type (opaque object)
70  *  @hideinitializer
71  */
72 typedef sg_cond_t xbt_cond_t;
73
74 /** @brief Creates a condition variable */
75 XBT_ATTRIB_DEPRECATED_v328("Please use sg_cond_init") static inline xbt_cond_t xbt_cond_init(void)
76 {
77   return sg_cond_init();
78 }
79
80 /** @brief Blocks onto the given condition variable */
81 XBT_ATTRIB_DEPRECATED_v328("Please use sg_cond_wait") static inline void xbt_cond_wait(xbt_cond_t cond,
82                                                                                        xbt_mutex_t mutex)
83 {
84   sg_cond_wait(cond, mutex);
85 }
86
87 /** @brief Blocks onto the given condition variable, but only for the given amount of time.
88  *  @return 0 on success, 1 on timeout */
89 XBT_ATTRIB_DEPRECATED_v328("Please use sg_cond_wait_for") static inline int xbt_cond_timedwait(xbt_cond_t cond,
90                                                                                                xbt_mutex_t mutex,
91                                                                                                double delay)
92 {
93   return sg_cond_wait_for(cond, mutex, delay);
94 }
95
96 /** @brief Signals the given mutex variable */
97 XBT_ATTRIB_DEPRECATED_v328("Please use sg_cond_notify_one") static inline void xbt_cond_signal(xbt_cond_t cond)
98 {
99   sg_cond_notify_one(cond);
100 }
101
102 /** @brief Broadcasts the given mutex variable */
103 XBT_ATTRIB_DEPRECATED_v328("Please use sg_cond_notify_all") static inline void xbt_cond_broadcast(xbt_cond_t cond)
104 {
105   sg_cond_notify_all(cond);
106 }
107
108 /** @brief Destroys the given mutex variable */
109 XBT_ATTRIB_DEPRECATED_v328("Please use sg_cond_destroy") static inline void xbt_cond_destroy(xbt_cond_t cond)
110 {
111   sg_cond_destroy(cond);
112 }
113
114 /** @} */
115
116 SG_END_DECL
117 #endif /* XBT_SYNCHRO_H */