XBT_PUBLIC(void) xbt_os_mutex_release(xbt_os_mutex_t mutex);
XBT_PUBLIC(void) xbt_os_mutex_destroy(xbt_os_mutex_t mutex);
-/** \brief Thread reentrant mutex data type (opaque structure) */
-typedef struct xbt_os_rmutex_ *xbt_os_rmutex_t;
-
-XBT_PUBLIC(xbt_os_rmutex_t) xbt_os_rmutex_init(void);
-XBT_PUBLIC(void) xbt_os_rmutex_acquire(xbt_os_rmutex_t rmutex);
-XBT_PUBLIC(void) xbt_os_rmutex_release(xbt_os_rmutex_t rmutex);
-XBT_PUBLIC(void) xbt_os_rmutex_destroy(xbt_os_rmutex_t rmutex);
-
/** \brief Thread condition data type (opaque structure) */
typedef struct xbt_os_cond_ *xbt_os_cond_t;
#include "xbt/xbt_os_thread.h"
int xbt_log_no_loc = 0; /* if set to true (with --log=no_loc), file localization will be omitted (for tesh tests) */
-static xbt_os_rmutex_t log_cat_init_mutex = NULL;
+static xbt_os_mutex_t log_cat_init_mutex = NULL;
/** \addtogroup XBT_log
*
xbt_log_default_layout = xbt_log_layout_simple_new(NULL);
_XBT_LOGV(XBT_LOG_ROOT_CAT).appender = xbt_log_default_appender;
_XBT_LOGV(XBT_LOG_ROOT_CAT).layout = xbt_log_default_layout;
- log_cat_init_mutex = xbt_os_rmutex_init();
+ log_cat_init_mutex = xbt_os_mutex_init();
}
static void xbt_log_connect_categories(void)
void xbt_log_postexit(void)
{
XBT_VERB("Exiting log");
- xbt_os_rmutex_destroy(log_cat_init_mutex);
+ xbt_os_mutex_destroy(log_cat_init_mutex);
xbt_dynar_free(&xbt_log_settings);
log_cat_exit(&_XBT_LOGV(XBT_LOG_ROOT_CAT));
}
if (setting->fmt) {
xbt_log_layout_set(category, xbt_log_layout_format_new(setting->fmt));
- XBT_DEBUG("Apply settings for category '%s': set format to %s",
- category->name, setting->fmt);
+ XBT_DEBUG("Apply settings for category '%s': set format to %s", category->name, setting->fmt);
}
if (setting->additivity != -1) {
{
#define _xbt_log_cat_init(a, b) (0)
- if (log_cat_init_mutex != NULL) {
- xbt_os_rmutex_acquire(log_cat_init_mutex);
- }
+ if (log_cat_init_mutex != NULL)
+ xbt_os_mutex_acquire(log_cat_init_mutex);
if (category->initialized) {
- if (log_cat_init_mutex != NULL) {
- xbt_os_rmutex_release(log_cat_init_mutex);
- }
+ if (log_cat_init_mutex != NULL)
+ xbt_os_mutex_release(log_cat_init_mutex);
return priority >= category->threshold;
}
}
category->initialized = 1;
- if (log_cat_init_mutex != NULL) {
- xbt_os_rmutex_release(log_cat_init_mutex);
- }
+ if (log_cat_init_mutex != NULL)
+ xbt_os_mutex_release(log_cat_init_mutex);
return priority >= category->threshold;
#undef _xbt_log_cat_init
/****** mutex related functions ******/
typedef struct xbt_os_mutex_ {
- /* KEEP IT IN SYNC WITH xbt_thread.c */
pthread_mutex_t m;
} s_xbt_os_mutex_t;
xbt_os_mutex_t xbt_os_mutex_init(void)
{
+ pthread_mutexattr_t Attr;
+ pthread_mutexattr_init(&Attr);
+ pthread_mutexattr_settype(&Attr, PTHREAD_MUTEX_RECURSIVE);
+
xbt_os_mutex_t res = xbt_new(s_xbt_os_mutex_t, 1);
- int errcode = pthread_mutex_init(&(res->m), NULL);
+ int errcode = pthread_mutex_init(&(res->m), &Attr);
xbt_assert(errcode==0, "pthread_mutex_init() failed: %s", strerror(errcode));
return res;
/***** condition related functions *****/
typedef struct xbt_os_cond_ {
- /* KEEP IT IN SYNC WITH xbt_thread.c */
pthread_cond_t c;
} s_xbt_os_cond_t;
xbt_os_thread_t thread = xbt_os_thread_self();
return thread ? thread->extra_data : NULL;
}
-
-/***** reentrant mutexes *****/
-typedef struct xbt_os_rmutex_ {
- xbt_os_mutex_t mutex;
- xbt_os_thread_t owner;
- int count;
-} s_xbt_os_rmutex_t;
-
-xbt_os_rmutex_t xbt_os_rmutex_init(void)
-{
- xbt_os_rmutex_t rmutex = xbt_new0(struct xbt_os_rmutex_, 1);
- rmutex->mutex = xbt_os_mutex_init();
- rmutex->owner = NULL;
- rmutex->count = 0;
- return rmutex;
-}
-
-void xbt_os_rmutex_acquire(xbt_os_rmutex_t rmutex)
-{
- xbt_os_thread_t self = xbt_os_thread_self();
-
- if (self == NULL) {
- /* the thread module is not initialized yet */
- rmutex->owner = NULL;
- return;
- }
-
- if (self != rmutex->owner) {
- xbt_os_mutex_acquire(rmutex->mutex);
- rmutex->owner = self;
- rmutex->count = 1;
- } else {
- rmutex->count++;
- }
-}
-
-void xbt_os_rmutex_release(xbt_os_rmutex_t rmutex)
-{
- if (rmutex->owner == NULL) {
- /* the thread module was not initialized */
- return;
- }
-
- xbt_assert(rmutex->owner == xbt_os_thread_self());
-
- if (--rmutex->count == 0) {
- rmutex->owner = NULL;
- xbt_os_mutex_release(rmutex->mutex);
- }
-}
-
-void xbt_os_rmutex_destroy(xbt_os_rmutex_t rmutex)
-{
- xbt_os_mutex_destroy(rmutex->mutex);
- xbt_free(rmutex);
-}