1 /* xbt/synchro.h -- Simulated synchronization */
3 /* Copyright (c) 2009-2020. The SimGrid Team. */
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. */
11 #include "simgrid/cond.h"
12 #include "simgrid/mutex.h"
13 #include <xbt/misc.h> /* SG_BEGIN_DECL */
15 #warning xbt/synchro.h is deprecated and will be removed in v3.28.
19 /** @addtogroup XBT_synchro
20 * @brief XBT synchronization tools
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.
29 /** @brief Thread mutex data type (opaque object)
32 typedef sg_mutex_t xbt_mutex_t;
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)
37 return sg_mutex_init();
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)
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
52 XBT_ATTRIB_DEPRECATED_v328("Please use sg_mutex_try_lock") static inline int xbt_mutex_try_acquire(xbt_mutex_t mutex)
54 return sg_mutex_try_lock(mutex);
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)
60 sg_mutex_unlock(mutex);
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)
66 sg_mutex_destroy(mutex);
69 /** @brief Thread condition data type (opaque object)
72 typedef sg_cond_t xbt_cond_t;
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)
77 return sg_cond_init();
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,
84 sg_cond_wait(cond, mutex);
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,
93 return sg_cond_wait_for(cond, mutex, delay);
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)
99 sg_cond_notify_one(cond);
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)
105 sg_cond_notify_all(cond);
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)
111 sg_cond_destroy(cond);
117 #endif /* XBT_SYNCHRO_H */