From: Christophe ThiƩry Date: Fri, 22 Apr 2011 11:40:09 +0000 (+0200) Subject: Attempt to allow initializing log categories before threads are X-Git-Tag: v3_6_rc3~110 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/c581d553ae0df2e3d481bce42644d2034c5e3dcd?hp=37a4ff2a0e7306c51b6b3ca04d1c2ba82157645f;ds=sidebyside Attempt to allow initializing log categories before threads are --- diff --git a/src/xbt/log.c b/src/xbt/log.c index 7ec846585d..e4030ef62a 100644 --- a/src/xbt/log.c +++ b/src/xbt/log.c @@ -691,9 +691,14 @@ int _xbt_log_cat_init(xbt_log_category_t category, { #define _xbt_log_cat_init(a, b) (0) - xbt_os_rmutex_acquire(log_cat_init_mutex); + if (log_cat_init_mutex != NULL) { + xbt_os_rmutex_acquire(log_cat_init_mutex); + } + if (category->threshold != xbt_log_priority_uninitialized) { - xbt_os_rmutex_release(log_cat_init_mutex); + if (log_cat_init_mutex != NULL) { + xbt_os_rmutex_release(log_cat_init_mutex); + } return priority >= category->threshold; } @@ -750,7 +755,9 @@ int _xbt_log_cat_init(xbt_log_category_t category, /* Apply the control */ if (!xbt_log_settings) { - xbt_os_rmutex_release(log_cat_init_mutex); + if (log_cat_init_mutex != NULL) { + xbt_os_rmutex_release(log_cat_init_mutex); + } return priority >= category->threshold; } @@ -777,7 +784,9 @@ int _xbt_log_cat_init(xbt_log_category_t category, category->name, xbt_log_priority_names[category->threshold], category->threshold); - xbt_os_rmutex_release(log_cat_init_mutex); + if (log_cat_init_mutex != NULL) { + xbt_os_rmutex_release(log_cat_init_mutex); + } return priority >= category->threshold; #undef _xbt_log_cat_init diff --git a/src/xbt/xbt_os_thread.c b/src/xbt/xbt_os_thread.c index 2bbec7e4e9..cdafb51495 100644 --- a/src/xbt/xbt_os_thread.c +++ b/src/xbt/xbt_os_thread.c @@ -1157,7 +1157,12 @@ xbt_os_rmutex_t xbt_os_rmutex_init(void) void xbt_os_rmutex_acquire(xbt_os_rmutex_t rmutex) { xbt_os_thread_t self = xbt_os_thread_self(); - xbt_assert(self != NULL, "Cannot get my own thread object (is the thread module initialized?)"); + + if (self == NULL) { + /* the thread module is not initialized yet */ + rmutex->owner = NULL; + return; + } if (self != rmutex->owner) { xbt_os_mutex_acquire(rmutex->mutex); @@ -1170,6 +1175,11 @@ void xbt_os_rmutex_acquire(xbt_os_rmutex_t rmutex) 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) {