diff --git a/src/backend/filedescriptor.c b/src/backend/filedescriptor.c index 64ab6c01b..876fc0768 100644 --- a/src/backend/filedescriptor.c +++ b/src/backend/filedescriptor.c @@ -98,7 +98,7 @@ lumiera_filedescriptor_registry_init (void) if (!registry) LUMIERA_DIE (NO_MEMORY); - lumiera_mutex_init (®istry_mutex, "filedescriptor_registry", &NOBUG_FLAG (mutex_dbg)); + lumiera_mutex_init (®istry_mutex, "filedescriptor_registry", &NOBUG_FLAG (mutex_dbg), NOBUG_CONTEXT); } void @@ -107,7 +107,7 @@ lumiera_filedescriptor_registry_destroy (void) TRACE (filedescriptor_dbg); REQUIRE (!psplay_nelements (registry)); - lumiera_mutex_destroy (®istry_mutex, &NOBUG_FLAG (mutex_dbg)); + lumiera_mutex_destroy (®istry_mutex, &NOBUG_FLAG (mutex_dbg), NOBUG_CONTEXT); if (registry) psplay_destroy (registry); @@ -277,7 +277,7 @@ lumiera_filedescriptor_new (LumieraFiledescriptor template) self->mmapings = NULL; llist_init (&self->files); - lumiera_mutex_init (&self->lock, "filedescriptor", &NOBUG_FLAG (mutex_dbg)); + lumiera_mutex_init (&self->lock, "filedescriptor", &NOBUG_FLAG (mutex_dbg), NOBUG_CONTEXT); return self; } @@ -310,7 +310,7 @@ lumiera_filedescriptor_delete (LumieraFiledescriptor self, const char* name) TODO ("release filehandle"); - lumiera_mutex_destroy (&self->lock, &NOBUG_FLAG (mutex_dbg)); + lumiera_mutex_destroy (&self->lock, &NOBUG_FLAG (mutex_dbg), NOBUG_CONTEXT); lumiera_free (self); } } diff --git a/src/backend/filehandlecache.c b/src/backend/filehandlecache.c index 73f9ecae6..f2cf4623b 100644 --- a/src/backend/filehandlecache.c +++ b/src/backend/filehandlecache.c @@ -45,7 +45,7 @@ lumiera_filehandlecache_new (int max_entries) lumiera_mrucache_init (&lumiera_fhcache->cache, lumiera_filehandle_destroy_node); lumiera_fhcache->available = max_entries; lumiera_fhcache->checked_out = 0; - lumiera_mutex_init (&lumiera_fhcache->lock, "filehandlecache", &NOBUG_FLAG (mutex_dbg)); + lumiera_mutex_init (&lumiera_fhcache->lock, "filehandlecache", &NOBUG_FLAG (mutex_dbg), NOBUG_CONTEXT); } @@ -56,7 +56,7 @@ lumiera_filehandlecache_delete (void) { REQUIRE (!lumiera_fhcache->checked_out, "Filehandles in use at shutdown"); lumiera_mrucache_destroy (&lumiera_fhcache->cache); - lumiera_mutex_destroy (&lumiera_fhcache->lock, &NOBUG_FLAG (mutex_dbg)); + lumiera_mutex_destroy (&lumiera_fhcache->lock, &NOBUG_FLAG (mutex_dbg), NOBUG_CONTEXT); lumiera_free (lumiera_fhcache); lumiera_fhcache = NULL; } diff --git a/src/backend/mmapcache.c b/src/backend/mmapcache.c index 1e416e68e..0580fd1c4 100644 --- a/src/backend/mmapcache.c +++ b/src/backend/mmapcache.c @@ -46,7 +46,7 @@ lumiera_mmapcache_new (size_t limit) lumiera_mcache->total = 0; lumiera_mcache->cached = 0; - lumiera_mutex_init (&lumiera_mcache->lock, "mmapcache", &NOBUG_FLAG (mutex_dbg)); + lumiera_mutex_init (&lumiera_mcache->lock, "mmapcache", &NOBUG_FLAG (mutex_dbg), NOBUG_CONTEXT); } @@ -58,7 +58,7 @@ lumiera_mmapcache_delete (void) { REQUIRE (lumiera_mcache->total == lumiera_mcache->cached, "MMaps still checked out at shutdown"); lumiera_mrucache_destroy (&lumiera_mcache->cache); - lumiera_mutex_destroy (&lumiera_mcache->lock, &NOBUG_FLAG (mutex_dbg)); + lumiera_mutex_destroy (&lumiera_mcache->lock, &NOBUG_FLAG (mutex_dbg), NOBUG_CONTEXT); free (lumiera_mcache); lumiera_mcache = NULL; } diff --git a/src/backend/mmapings.c b/src/backend/mmapings.c index 3e052ce91..f3fa4edb7 100644 --- a/src/backend/mmapings.c +++ b/src/backend/mmapings.c @@ -44,7 +44,7 @@ lumiera_mmapings_init (LumieraMMapings self, LumieraFile file, size_t chunksize) self->descriptor = file->descriptor; self->chunksize = chunksize; - lumiera_mutex_init (&self->lock, "mmapings", &NOBUG_FLAG(mutex_dbg)); + lumiera_mutex_init (&self->lock, "mmapings", &NOBUG_FLAG(mutex_dbg), NOBUG_CONTEXT); return self; } @@ -63,7 +63,7 @@ lumiera_mmapings_destroy (LumieraMMapings self) lumiera_mmap_delete (mmap); } - lumiera_mutex_destroy (&self->lock, &NOBUG_FLAG(mutex_dbg)); + lumiera_mutex_destroy (&self->lock, &NOBUG_FLAG(mutex_dbg), NOBUG_CONTEXT); return self; } diff --git a/src/common/config.c b/src/common/config.c index b3a2fb745..4e62ae4d9 100644 --- a/src/common/config.c +++ b/src/common/config.c @@ -112,7 +112,7 @@ lumiera_config_init (const char* path) lumiera_configitem_init (&lumiera_global_config->files); lumiera_configitem_init (&lumiera_global_config->TODO_unknown); - lumiera_mutex_init (&lumiera_global_config->lock, "config mutex", &NOBUG_FLAG (mutex_dbg)); + lumiera_mutex_init (&lumiera_global_config->lock, "config mutex", &NOBUG_FLAG (mutex_dbg), NOBUG_CONTEXT); lumiera_config_setdefault (lumiera_tmpbuf_snprintf (SIZE_MAX, "config.path = %s", path)); @@ -131,7 +131,7 @@ lumiera_config_destroy () TRACE (config_dbg); if (lumiera_global_config) { - lumiera_mutex_destroy (&lumiera_global_config->lock, &NOBUG_FLAG (mutex_dbg)); + lumiera_mutex_destroy (&lumiera_global_config->lock, &NOBUG_FLAG (mutex_dbg), NOBUG_CONTEXT); lumiera_configitem_destroy (&lumiera_global_config->defaults, &lumiera_global_config->keys); lumiera_configitem_destroy (&lumiera_global_config->files, &lumiera_global_config->keys); lumiera_configitem_destroy (&lumiera_global_config->TODO_unknown, &lumiera_global_config->keys); diff --git a/src/common/interfaceregistry.c b/src/common/interfaceregistry.c index 3b67e77e1..1637e48df 100644 --- a/src/common/interfaceregistry.c +++ b/src/common/interfaceregistry.c @@ -108,7 +108,7 @@ lumiera_interfaceregistry_init (void) if (!lumiera_pluginregistry) LUMIERA_DIE (ERRNO); - lumiera_recmutex_init (&lumiera_interface_mutex, "interfaceregistry", &NOBUG_FLAG(interfaceregistry)); + lumiera_recmutex_init (&lumiera_interface_mutex, "interfaceregistry", &NOBUG_FLAG(interfaceregistry), NOBUG_CONTEXT); lumiera_interface_init (); } @@ -125,7 +125,7 @@ lumiera_interfaceregistry_destroy (void) psplay_delete (lumiera_pluginregistry); lumiera_pluginregistry = NULL; - lumiera_recmutex_destroy (&lumiera_interface_mutex, &NOBUG_FLAG(mutex_dbg)); + lumiera_recmutex_destroy (&lumiera_interface_mutex, &NOBUG_FLAG(mutex_dbg), NOBUG_CONTEXT); REQUIRE (!psplay_nelements (lumiera_interfaceregistry), "some interfaces still registered at shutdown"); diff --git a/src/lib/condition.c b/src/lib/condition.c index 432ba52c9..97a0593d9 100644 --- a/src/lib/condition.c +++ b/src/lib/condition.c @@ -28,25 +28,30 @@ LumieraCondition -lumiera_condition_init (LumieraCondition self, const char* purpose, struct nobug_flag* flag) +lumiera_condition_init (LumieraCondition self, + const char* purpose, + struct nobug_flag* flag, + const struct nobug_context ctx) { if (self) { pthread_cond_init (&self->cond, NULL); pthread_mutex_init (&self->cndmutex, NULL); NOBUG_RESOURCE_HANDLE_INIT (self->rh); - NOBUG_RESOURCE_ANNOUNCE_RAW (flag, "cond_var", purpose, self, self->rh); + NOBUG_RESOURCE_ANNOUNCE_RAW_CTX (flag, "cond_var", purpose, self, self->rh, ctx); } return self; } LumieraCondition -lumiera_condition_destroy (LumieraCondition self, struct nobug_flag* flag) +lumiera_condition_destroy (LumieraCondition self, + struct nobug_flag* flag, + const struct nobug_context ctx) { if (self) { - NOBUG_RESOURCE_FORGET_RAW (flag, self->rh); + NOBUG_RESOURCE_FORGET_RAW_CTX (flag, self->rh, ctx); if (pthread_mutex_destroy (&self->cndmutex)) LUMIERA_DIE (LOCK_DESTROY); diff --git a/src/lib/condition.h b/src/lib/condition.h index 51abfb61a..ea0d72871 100644 --- a/src/lib/condition.h +++ b/src/lib/condition.h @@ -46,39 +46,41 @@ * @param nobugflag NoBug flag used to log actions on the condition * @param cnd Condition variable to be locked */ -#define LUMIERA_CONDITION_SECTION(nobugflag, cnd) \ - for (lumiera_sectionlock NOBUG_CLEANUP(lumiera_sectionlock_ensureunlocked) \ - lumiera_lock_section_ = { \ - cnd, (lumiera_sectionlock_unlock_fn) lumiera_condition_unlock \ - NOBUG_ALPHA_COMMA(&NOBUG_FLAG(nobugflag)) NOBUG_ALPHA_COMMA_NULL}; \ - ({ \ - if (lumiera_lock_section_.lock) \ - lumiera_lock_section_.lock = \ - lumiera_condition_lock (cnd, &NOBUG_FLAG(nobugflag), &lumiera_lock_section_.rh); \ - lumiera_lock_section_.lock; \ - }); \ - ({ \ - LUMIERA_CONDITION_SECTION_UNLOCK; \ +#define LUMIERA_CONDITION_SECTION(nobugflag, cnd) \ + for (lumiera_sectionlock NOBUG_CLEANUP(lumiera_sectionlock_ensureunlocked) \ + lumiera_lock_section_ = { \ + cnd, (lumiera_sectionlock_unlock_fn) lumiera_condition_unlock \ + NOBUG_ALPHA_COMMA(&NOBUG_FLAG(nobugflag)) NOBUG_ALPHA_COMMA_NULL}; \ + ({ \ + if (lumiera_lock_section_.lock) \ + lumiera_lock_section_.lock = \ + lumiera_condition_lock (cnd, &NOBUG_FLAG(nobugflag), \ + &lumiera_lock_section_.rh, NOBUG_CONTEXT); \ + lumiera_lock_section_.lock; \ + }); \ + ({ \ + LUMIERA_CONDITION_SECTION_UNLOCK; \ })) -#define LUMIERA_CONDITION_SECTION_CHAIN(nobugflag, cnd) \ - for (lumiera_sectionlock *lumiera_lock_section_old_ = &lumiera_lock_section_, \ - NOBUG_CLEANUP(lumiera_sectionlock_ensureunlocked) lumiera_lock_section_ = { \ - cnd, (lumiera_sectionlock_unlock_fn) lumiera_condition_unlock \ - NOBUG_ALPHA_COMMA(&NOBUG_FLAG(nobugflag)) NOBUG_ALPHA_COMMA_NULL}; \ - ({ \ - if (lumiera_lock_section_.lock) \ - { \ - REQUIRE (lumiera_lock_section_old_->lock, "section prematurely unlocked"); \ - lumiera_lock_section_.lock = \ - lumiera_condition_lock (cnd, &NOBUG_FLAG(nobugflag), &lumiera_lock_section_.rh); \ - LUMIERA_SECTION_UNLOCK_(lumiera_lock_section_old_); \ - } \ - lumiera_lock_section_.lock; \ - }); \ - ({ \ - LUMIERA_CONDITION_SECTION_UNLOCK; \ +#define LUMIERA_CONDITION_SECTION_CHAIN(nobugflag, cnd) \ + for (lumiera_sectionlock *lumiera_lock_section_old_ = &lumiera_lock_section_, \ + NOBUG_CLEANUP(lumiera_sectionlock_ensureunlocked) lumiera_lock_section_ = { \ + cnd, (lumiera_sectionlock_unlock_fn) lumiera_condition_unlock \ + NOBUG_ALPHA_COMMA(&NOBUG_FLAG(nobugflag)) NOBUG_ALPHA_COMMA_NULL}; \ + ({ \ + if (lumiera_lock_section_.lock) \ + { \ + REQUIRE (lumiera_lock_section_old_->lock, "section prematurely unlocked"); \ + lumiera_lock_section_.lock = \ + lumiera_condition_lock (cnd, &NOBUG_FLAG(nobugflag), \ + &lumiera_lock_section_.rh, NOBUG_CONTEXT); \ + LUMIERA_SECTION_UNLOCK_(lumiera_lock_section_old_); \ + } \ + lumiera_lock_section_.lock; \ + }); \ + ({ \ + LUMIERA_CONDITION_SECTION_UNLOCK; \ })) @@ -96,7 +98,8 @@ REQUIRE (lumiera_lock_section_.lock, "Condition mutex not locked"); \ lumiera_condition_wait (lumiera_lock_section_.lock, \ lumiera_lock_section_.flag, \ - &lumiera_lock_section_.rh); \ + &lumiera_lock_section_.rh, \ + NOBUG_CONTEXT); \ } while (!(expr)) @@ -113,7 +116,8 @@ if (!lumiera_condition_timedwait (lumiera_lock_section_.lock, \ timeout, \ lumiera_lock_section_.flag, \ - &lumiera_lock_section_.rh)) \ + &lumiera_lock_section_.rh, \ + NOBUG_CONTEXT)) \ break; \ } while (!(expr)) @@ -127,7 +131,8 @@ do { \ REQUIRE (lumiera_lock_section_.lock, "Condition mutex not locked"); \ lumiera_condition_signal (lumiera_lock_section_.lock, \ - lumiera_lock_section_.flag); \ + lumiera_lock_section_.flag, \ + NOBUG_CONTEXT); \ } while (0) @@ -140,7 +145,8 @@ do { \ REQUIRE (lumiera_lock_section_.lock, "Condition mutex not locked"); \ lumiera_condition_broadcast (lumiera_lock_section_.lock, \ - lumiera_lock_section_.flag); \ + lumiera_lock_section_.flag, \ + NOBUG_CONTEXT); \ } while (0) @@ -164,7 +170,10 @@ typedef lumiera_condition* LumieraCondition; * @return self as given */ LumieraCondition -lumiera_condition_init (LumieraCondition self, const char* purpose, struct nobug_flag* flag); +lumiera_condition_init (LumieraCondition self, + const char* purpose, + struct nobug_flag* flag, + const struct nobug_context ctx); /** @@ -173,20 +182,25 @@ lumiera_condition_init (LumieraCondition self, const char* purpose, struct nobug * @return self as given */ LumieraCondition -lumiera_condition_destroy (LumieraCondition self, struct nobug_flag* flag); +lumiera_condition_destroy (LumieraCondition self, + struct nobug_flag* flag, + const struct nobug_context ctx); static inline LumieraCondition -lumiera_condition_lock (LumieraCondition self, struct nobug_flag* flag, struct nobug_resource_user** handle) +lumiera_condition_lock (LumieraCondition self, + struct nobug_flag* flag, + struct nobug_resource_user** handle, + const struct nobug_context ctx) { if (self) { - RESOURCE_WAIT (NOBUG_FLAG_RAW(flag), self->rh, "acquire condvar", *handle); + NOBUG_RESOURCE_WAIT_CTX (NOBUG_FLAG_RAW(flag), self->rh, "acquire condvar", *handle, ctx); if (pthread_mutex_lock (&self->cndmutex)) LUMIERA_DIE (LOCK_ACQUIRE); /* never reached (in a correct program) */ - RESOURCE_STATE (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_EXCLUSIVE, *handle); + NOBUG_RESOURCE_STATE_CTX (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_EXCLUSIVE, *handle, ctx); } return self; @@ -194,22 +208,25 @@ lumiera_condition_lock (LumieraCondition self, struct nobug_flag* flag, struct n static inline LumieraCondition -lumiera_condition_trylock (LumieraCondition self, struct nobug_flag* flag, struct nobug_resource_user** handle) +lumiera_condition_trylock (LumieraCondition self, + struct nobug_flag* flag, + struct nobug_resource_user** handle, + const struct nobug_context ctx) { if (self) { - NOBUG_RESOURCE_TRY (NOBUG_FLAG_RAW(flag), self->rh, "try acquire condvar", *handle); + NOBUG_RESOURCE_TRY_CTX (NOBUG_FLAG_RAW(flag), self->rh, "try acquire condvar", *handle, ctx); int err = pthread_mutex_trylock (&self->cndmutex); if (!err) { - RESOURCE_STATE (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_EXCLUSIVE, *handle); + NOBUG_RESOURCE_STATE_CTX (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_EXCLUSIVE, *handle, ctx); } else { - NOBUG_RESOURCE_LEAVE_RAW(flag, *handle) /*{}*/; - lumiera_lockerror_set (err, flag, __func__); + NOBUG_RESOURCE_LEAVE_RAW_CTX (flag, *handle, ctx) /*{}*/; + lumiera_lockerror_set (err, flag, ctx); return NULL; } } @@ -222,22 +239,23 @@ static inline LumieraCondition lumiera_condition_timedlock (LumieraCondition self, const struct timespec* timeout, struct nobug_flag* flag, - struct nobug_resource_user** handle) + struct nobug_resource_user** handle, + const struct nobug_context ctx) { if (self) { - NOBUG_RESOURCE_TRY (NOBUG_FLAG_RAW(flag), self->rh, "timed acquire condvar", *handle); + NOBUG_RESOURCE_TRY_CTX (NOBUG_FLAG_RAW(flag), self->rh, "timed acquire condvar", *handle, ctx); int err = pthread_mutex_timedlock (&self->cndmutex, timeout); if (!err) { - RESOURCE_STATE (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_EXCLUSIVE, *handle); + NOBUG_RESOURCE_STATE_CTX (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_EXCLUSIVE, *handle, ctx); } else { - NOBUG_RESOURCE_LEAVE_RAW(flag, *handle) /*{}*/; - lumiera_lockerror_set (err, flag, __func__); + NOBUG_RESOURCE_LEAVE_RAW_CTX (flag, *handle, ctx) /*{}*/; + lumiera_lockerror_set (err, flag, ctx); return NULL; } } @@ -247,15 +265,18 @@ lumiera_condition_timedlock (LumieraCondition self, static inline LumieraCondition -lumiera_condition_wait (LumieraCondition self, struct nobug_flag* flag, struct nobug_resource_user** handle) +lumiera_condition_wait (LumieraCondition self, + struct nobug_flag* flag, + struct nobug_resource_user** handle, + const struct nobug_context ctx) { if (self) { - NOBUG_RESOURCE_STATE_RAW (flag, NOBUG_RESOURCE_WAITING, *handle); + NOBUG_RESOURCE_STATE_RAW_CTX (flag, NOBUG_RESOURCE_WAITING, *handle, ctx); pthread_cond_wait (&self->cond, &self->cndmutex); - NOBUG_RESOURCE_STATE_RAW (flag, NOBUG_RESOURCE_EXCLUSIVE, *handle); + NOBUG_RESOURCE_STATE_RAW_CTX (flag, NOBUG_RESOURCE_EXCLUSIVE, *handle, ctx); } return self; } @@ -265,22 +286,23 @@ static inline LumieraCondition lumiera_condition_timedwait (LumieraCondition self, const struct timespec* timeout, struct nobug_flag* flag, - struct nobug_resource_user** handle) + struct nobug_resource_user** handle, + const struct nobug_context ctx) { if (self) { - NOBUG_RESOURCE_STATE_RAW (flag, NOBUG_RESOURCE_WAITING, *handle); + NOBUG_RESOURCE_STATE_RAW_CTX (flag, NOBUG_RESOURCE_WAITING, *handle, ctx); int err; do { err = pthread_cond_timedwait (&self->cond, &self->cndmutex, timeout); } while(err == EINTR); - NOBUG_RESOURCE_STATE_RAW (flag, NOBUG_RESOURCE_EXCLUSIVE, *handle); + NOBUG_RESOURCE_STATE_RAW_CTX (flag, NOBUG_RESOURCE_EXCLUSIVE, *handle, ctx); if (err) { - lumiera_lockerror_set (err, flag, __func__); + lumiera_lockerror_set (err, flag, ctx); return NULL; } } @@ -291,27 +313,34 @@ lumiera_condition_timedwait (LumieraCondition self, static inline void -lumiera_condition_signal (LumieraCondition self, struct nobug_flag* flag) +lumiera_condition_signal (LumieraCondition self, + struct nobug_flag* flag, + const struct nobug_context ctx) { - TRACE(NOBUG_FLAG_RAW(flag), "Signal %p", self); + NOBUG_TRACE_CTX (NOBUG_FLAG_RAW(flag), ctx, "Signal %p", self); pthread_cond_signal (&self->cond); } static inline void -lumiera_condition_broadcast (LumieraCondition self, struct nobug_flag* flag) +lumiera_condition_broadcast (LumieraCondition self, + struct nobug_flag* flag, + const struct nobug_context ctx) { - TRACE(NOBUG_FLAG_RAW(flag), "Broadcast %p", self); + NOBUG_TRACE_CTX(NOBUG_FLAG_RAW(flag), ctx, "Broadcast %p", self); pthread_cond_broadcast (&self->cond); } static inline void -lumiera_condition_unlock (LumieraCondition self, struct nobug_flag* flag, struct nobug_resource_user** handle) +lumiera_condition_unlock (LumieraCondition self, + struct nobug_flag* flag, + struct nobug_resource_user** handle, + const struct nobug_context ctx) { - REQUIRE(self); + NOBUG_REQUIRE_CTX (self, ctx); - NOBUG_RESOURCE_LEAVE_RAW(flag, *handle) + NOBUG_RESOURCE_LEAVE_RAW_CTX (flag, *handle, ctx) { if (pthread_mutex_unlock (&self->cndmutex)) LUMIERA_DIE (LOCK_RELEASE); /* never reached (in a correct program) */ diff --git a/src/lib/lockerror.c b/src/lib/lockerror.c index 6c53b8fbb..bad423698 100644 --- a/src/lib/lockerror.c +++ b/src/lib/lockerror.c @@ -39,32 +39,32 @@ LUMIERA_ERROR_DEFINE (LOCK_AGAIN, "too much recursive locks"); void -lumiera_lockerror_set (int err, struct nobug_flag* flag, const char* extra) +lumiera_lockerror_set (int err, struct nobug_flag* flag, const struct nobug_context ctx) { switch (err) { case 0: break; case EINVAL: - LUMIERA_ERROR_SET_ALERT(NOBUG_FLAG_RAW(flag), LOCK_INVAL, extra); + LUMIERA_ERROR_SET_ALERT(NOBUG_FLAG_RAW(flag), LOCK_INVAL, ctx.func); break; case EBUSY: - LUMIERA_ERROR_SET(NOBUG_FLAG_RAW(flag), LOCK_BUSY, extra); + LUMIERA_ERROR_SET(NOBUG_FLAG_RAW(flag), LOCK_BUSY, ctx.func); break; case EDEADLK: - LUMIERA_ERROR_SET(NOBUG_FLAG_RAW(flag), LOCK_DEADLK, extra); + LUMIERA_ERROR_SET(NOBUG_FLAG_RAW(flag), LOCK_DEADLK, ctx.func); break; case EPERM: - LUMIERA_ERROR_SET_ALERT(NOBUG_FLAG_RAW(flag), LOCK_PERM, extra); + LUMIERA_ERROR_SET_ALERT(NOBUG_FLAG_RAW(flag), LOCK_PERM, ctx.func); break; case ETIMEDOUT: - LUMIERA_ERROR_SET(NOBUG_FLAG_RAW(flag), LOCK_TIMEOUT, extra); + LUMIERA_ERROR_SET(NOBUG_FLAG_RAW(flag), LOCK_TIMEOUT, ctx.func); break; case EAGAIN: - LUMIERA_ERROR_SET_WARNING(NOBUG_FLAG_RAW(flag), LOCK_AGAIN, extra); + LUMIERA_ERROR_SET_WARNING(NOBUG_FLAG_RAW(flag), LOCK_AGAIN, ctx.func); break; default: - LUMIERA_ERROR_SET_CRITICAL(NOBUG_FLAG_RAW(flag), UNKNOWN, extra); + LUMIERA_ERROR_SET_CRITICAL(NOBUG_FLAG_RAW(flag), UNKNOWN, ctx.func); break; } } diff --git a/src/lib/lockerror.h b/src/lib/lockerror.h index 4916d8a57..27ff5dbe3 100644 --- a/src/lib/lockerror.h +++ b/src/lib/lockerror.h @@ -41,7 +41,7 @@ LUMIERA_ERROR_DECLARE (LOCK_AGAIN); * Translate pthread error code into lumiera error */ void -lumiera_lockerror_set (int err, struct nobug_flag* flag, const char* extra); +lumiera_lockerror_set (int err, struct nobug_flag* flag, const struct nobug_context ctx); #endif /* diff --git a/src/lib/mutex.c b/src/lib/mutex.c index bdbc6662e..eb1e0dc93 100644 --- a/src/lib/mutex.c +++ b/src/lib/mutex.c @@ -27,24 +27,29 @@ */ LumieraMutex -lumiera_mutex_init (LumieraMutex self, const char* purpose, struct nobug_flag* flag) +lumiera_mutex_init (LumieraMutex self, + const char* purpose, + struct nobug_flag* flag, + const struct nobug_context ctx) { if (self) { pthread_mutex_init (&self->mutex, NULL); NOBUG_RESOURCE_HANDLE_INIT (self->rh); - NOBUG_RESOURCE_ANNOUNCE_RAW (flag, "mutex", purpose, self, self->rh); + NOBUG_RESOURCE_ANNOUNCE_RAW_CTX (flag, "mutex", purpose, self, self->rh, ctx); } return self; } LumieraMutex -lumiera_mutex_destroy (LumieraMutex self, struct nobug_flag* flag) +lumiera_mutex_destroy (LumieraMutex self, + struct nobug_flag* flag, + const struct nobug_context ctx) { if (self) { - NOBUG_RESOURCE_FORGET_RAW (flag, self->rh); + NOBUG_RESOURCE_FORGET_RAW_CTX (flag, self->rh, ctx); if (pthread_mutex_destroy (&self->mutex)) LUMIERA_DIE (LOCK_DESTROY); } diff --git a/src/lib/mutex.h b/src/lib/mutex.h index 04a859b91..2f60d46fd 100644 --- a/src/lib/mutex.h +++ b/src/lib/mutex.h @@ -38,19 +38,20 @@ /** * Mutual exclusive section. */ -#define LUMIERA_MUTEX_SECTION(nobugflag, mtx) \ - for (lumiera_sectionlock NOBUG_CLEANUP(lumiera_sectionlock_ensureunlocked) \ - lumiera_lock_section_ = { \ - mtx, (lumiera_sectionlock_unlock_fn) lumiera_mutex_unlock \ - NOBUG_ALPHA_COMMA(&NOBUG_FLAG(nobugflag)) NOBUG_ALPHA_COMMA_NULL}; \ - ({ \ - if (lumiera_lock_section_.lock) \ - lumiera_lock_section_.lock = \ - lumiera_mutex_lock (mtx, &NOBUG_FLAG(nobugflag), &lumiera_lock_section_.rh); \ - lumiera_lock_section_.lock; \ - }); \ - ({ \ - LUMIERA_MUTEX_SECTION_UNLOCK; \ +#define LUMIERA_MUTEX_SECTION(nobugflag, mtx) \ + for (lumiera_sectionlock NOBUG_CLEANUP(lumiera_sectionlock_ensureunlocked) \ + lumiera_lock_section_ = { \ + mtx, (lumiera_sectionlock_unlock_fn) lumiera_mutex_unlock \ + NOBUG_ALPHA_COMMA(&NOBUG_FLAG(nobugflag)) NOBUG_ALPHA_COMMA_NULL}; \ + ({ \ + if (lumiera_lock_section_.lock) \ + lumiera_lock_section_.lock = \ + lumiera_mutex_lock (mtx, &NOBUG_FLAG(nobugflag), \ + &lumiera_lock_section_.rh, NOBUG_CONTEXT); \ + lumiera_lock_section_.lock; \ + }); \ + ({ \ + LUMIERA_MUTEX_SECTION_UNLOCK; \ })) @@ -61,23 +62,24 @@ * This macro should only be used inside LUMIERA_MUTEX_SECTION and should be * called on the correct mutexes, period. */ -#define LUMIERA_MUTEX_SECTION_CHAIN(nobugflag, mtx) \ - for (lumiera_sectionlock *lumiera_lock_section_old_ = &lumiera_lock_section_, \ - NOBUG_CLEANUP(lumiera_sectionlock_ensureunlocked) lumiera_lock_section_ = { \ - mtx, (lumiera_sectionlock_unlock_fn) lumiera_mutex_unlock \ - NOBUG_ALPHA_COMMA(&NOBUG_FLAG(nobugflag)) NOBUG_ALPHA_COMMA_NULL}; \ - ({ \ - if (lumiera_lock_section_.lock) \ - { \ - REQUIRE (lumiera_lock_section_old_->lock, "section prematurely unlocked"); \ - lumiera_lock_section_.lock = \ - lumiera_mutex_lock (mtx, &NOBUG_FLAG(nobugflag), &lumiera_lock_section_.rh); \ - LUMIERA_SECTION_UNLOCK_(lumiera_lock_section_old_); \ - } \ - lumiera_lock_section_.lock; \ - }); \ - ({ \ - LUMIERA_MUTEX_SECTION_UNLOCK; \ +#define LUMIERA_MUTEX_SECTION_CHAIN(nobugflag, mtx) \ + for (lumiera_sectionlock *lumiera_lock_section_old_ = &lumiera_lock_section_, \ + NOBUG_CLEANUP(lumiera_sectionlock_ensureunlocked) lumiera_lock_section_ = { \ + mtx, (lumiera_sectionlock_unlock_fn) lumiera_mutex_unlock \ + NOBUG_ALPHA_COMMA(&NOBUG_FLAG(nobugflag)) NOBUG_ALPHA_COMMA_NULL}; \ + ({ \ + if (lumiera_lock_section_.lock) \ + { \ + REQUIRE (lumiera_lock_section_old_->lock, "section prematurely unlocked"); \ + lumiera_lock_section_.lock = \ + lumiera_mutex_lock (mtx, &NOBUG_FLAG(nobugflag), \ + &lumiera_lock_section_.rh, NOBUG_CONTEXT); \ + LUMIERA_SECTION_UNLOCK_(lumiera_lock_section_old_); \ + } \ + lumiera_lock_section_.lock; \ + }); \ + ({ \ + LUMIERA_MUTEX_SECTION_UNLOCK; \ })) @@ -107,7 +109,10 @@ typedef lumiera_mutex* LumieraMutex; * @return self as given */ LumieraMutex -lumiera_mutex_init (LumieraMutex self, const char* purpose, struct nobug_flag* flag); +lumiera_mutex_init (LumieraMutex self, + const char* purpose, + struct nobug_flag* flag, + const struct nobug_context ctx); /** * Destroy a mutex variable @@ -116,7 +121,9 @@ lumiera_mutex_init (LumieraMutex self, const char* purpose, struct nobug_flag* f * @return self as given */ LumieraMutex -lumiera_mutex_destroy (LumieraMutex self, struct nobug_flag* flag); +lumiera_mutex_destroy (LumieraMutex self, + struct nobug_flag* flag, + const struct nobug_context ctx); /** @@ -128,16 +135,19 @@ lumiera_mutex_destroy (LumieraMutex self, struct nobug_flag* flag); * @return self as given */ static inline LumieraMutex -lumiera_mutex_lock (LumieraMutex self, struct nobug_flag* flag, struct nobug_resource_user** handle) +lumiera_mutex_lock (LumieraMutex self, + struct nobug_flag* flag, + struct nobug_resource_user** handle, + const struct nobug_context ctx) { if (self) { - RESOURCE_WAIT (NOBUG_FLAG_RAW(flag), self->rh, "acquire mutex", *handle); + NOBUG_RESOURCE_WAIT_CTX (NOBUG_FLAG_RAW(flag), self->rh, "acquire mutex", *handle, ctx); if (pthread_mutex_lock (&self->mutex)) LUMIERA_DIE (LOCK_ACQUIRE); /* never reached (in a correct program) */ - RESOURCE_STATE (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_EXCLUSIVE, *handle); + NOBUG_RESOURCE_STATE_CTX (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_EXCLUSIVE, *handle, ctx); } return self; @@ -152,22 +162,25 @@ lumiera_mutex_lock (LumieraMutex self, struct nobug_flag* flag, struct nobug_res * @return self as given or NULL on error, lumiera_error gets set approbiately */ static inline LumieraMutex -lumiera_mutex_trylock (LumieraMutex self, struct nobug_flag* flag, struct nobug_resource_user** handle) +lumiera_mutex_trylock (LumieraMutex self, + struct nobug_flag* flag, + struct nobug_resource_user** handle, + const struct nobug_context ctx) { if (self) { - NOBUG_RESOURCE_TRY (NOBUG_FLAG_RAW(flag), self->rh, "try acquire mutex", *handle); + NOBUG_RESOURCE_TRY_CTX (NOBUG_FLAG_RAW(flag), self->rh, "try acquire mutex", *handle, ctx); int err = pthread_mutex_trylock (&self->mutex); if (!err) { - RESOURCE_STATE (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_EXCLUSIVE, *handle); + NOBUG_RESOURCE_STATE_CTX (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_EXCLUSIVE, *handle, ctx); } else { - NOBUG_RESOURCE_LEAVE_RAW(flag, *handle) /*{}*/; - lumiera_lockerror_set (err, flag, __func__); + NOBUG_RESOURCE_LEAVE_RAW_CTX (flag, *handle, ctx) /*{}*/; + lumiera_lockerror_set (err, flag, ctx); return NULL; } } @@ -187,22 +200,23 @@ static inline LumieraMutex lumiera_mutex_timedlock (LumieraMutex self, const struct timespec* timeout, struct nobug_flag* flag, - struct nobug_resource_user** handle) + struct nobug_resource_user** handle, + const struct nobug_context ctx) { if (self) { - NOBUG_RESOURCE_TRY (NOBUG_FLAG_RAW(flag), self->rh, "timed acquire mutex", *handle); + NOBUG_RESOURCE_TRY_CTX (NOBUG_FLAG_RAW(flag), self->rh, "timed acquire mutex", *handle, ctx); int err = pthread_mutex_timedlock (&self->mutex, timeout); if (!err) { - RESOURCE_STATE (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_EXCLUSIVE, *handle); + NOBUG_RESOURCE_STATE_CTX (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_EXCLUSIVE, *handle, ctx); } else { - NOBUG_RESOURCE_LEAVE_RAW(flag, *handle) /*{}*/; - lumiera_lockerror_set (err, flag, __func__); + NOBUG_RESOURCE_LEAVE_RAW_CTX (flag, *handle, ctx) /*{}*/; + lumiera_lockerror_set (err, flag, ctx); return NULL; } } @@ -219,11 +233,14 @@ lumiera_mutex_timedlock (LumieraMutex self, * @param handle pointer to nobug user handle (NULL in beta and release builds) */ static inline void -lumiera_mutex_unlock (LumieraMutex self, struct nobug_flag* flag, struct nobug_resource_user** handle) +lumiera_mutex_unlock (LumieraMutex self, + struct nobug_flag* flag, + struct nobug_resource_user** handle, + const struct nobug_context ctx) { - REQUIRE(self); + NOBUG_REQUIRE_CTX (self, ctx); - NOBUG_RESOURCE_LEAVE_RAW(flag, *handle) + NOBUG_RESOURCE_LEAVE_RAW_CTX (flag, *handle, ctx) { if (pthread_mutex_unlock (&self->mutex)) LUMIERA_DIE (LOCK_RELEASE); /* never reached (in a correct program) */ diff --git a/src/lib/reccondition.c b/src/lib/reccondition.c index bf9631ebb..f31154a34 100644 --- a/src/lib/reccondition.c +++ b/src/lib/reccondition.c @@ -39,7 +39,10 @@ static void recursive_mutexattr_init() LumieraReccondition -lumiera_reccondition_init (LumieraReccondition self, const char* purpose, struct nobug_flag* flag) +lumiera_reccondition_init (LumieraReccondition self, + const char* purpose, + struct nobug_flag* flag, + const struct nobug_context ctx) { if (self) { @@ -49,18 +52,20 @@ lumiera_reccondition_init (LumieraReccondition self, const char* purpose, struct pthread_cond_init (&self->cond, NULL); pthread_mutex_init (&self->reccndmutex, &recursive_mutexattr); NOBUG_RESOURCE_HANDLE_INIT (self->rh); - NOBUG_RESOURCE_ANNOUNCE_RAW (flag, "reccond_var", purpose, self, self->rh); + NOBUG_RESOURCE_ANNOUNCE_RAW_CTX (flag, "reccond_var", purpose, self, self->rh, ctx); } return self; } LumieraReccondition -lumiera_reccondition_destroy (LumieraReccondition self, struct nobug_flag* flag) +lumiera_reccondition_destroy (LumieraReccondition self, + struct nobug_flag* flag, + const struct nobug_context ctx) { if (self) { - NOBUG_RESOURCE_FORGET_RAW (flag, self->rh); + NOBUG_RESOURCE_FORGET_RAW_CTX (flag, self->rh, ctx); if (pthread_mutex_destroy (&self->reccndmutex)) LUMIERA_DIE (LOCK_DESTROY); diff --git a/src/lib/reccondition.h b/src/lib/reccondition.h index bbb321861..3572da05a 100644 --- a/src/lib/reccondition.h +++ b/src/lib/reccondition.h @@ -44,40 +44,42 @@ * @param nobugflag NoBug flag used to log actions on the condition * @param cnd Condition variable to be locked */ -#define LUMIERA_RECCONDITION_SECTION(nobugflag, cnd) \ - for (lumiera_sectionlock NOBUG_CLEANUP(lumiera_sectionlock_ensureunlocked) \ - lumiera_lock_section_ = { \ - cnd, (lumiera_sectionlock_unlock_fn) lumiera_reccondition_unlock \ - NOBUG_ALPHA_COMMA(&NOBUG_FLAG(nobugflag)) NOBUG_ALPHA_COMMA_NULL}; \ - ({ \ - if (lumiera_lock_section_.lock) \ - lumiera_lock_section_.lock = \ - lumiera_reccondition_lock (cnd, &NOBUG_FLAG(nobugflag), &lumiera_lock_section_.rh); \ - lumiera_lock_section_.lock; \ - }); \ - ({ \ - LUMIERA_RECCONDITION_SECTION_UNLOCK; \ +#define LUMIERA_RECCONDITION_SECTION(nobugflag, cnd) \ + for (lumiera_sectionlock NOBUG_CLEANUP(lumiera_sectionlock_ensureunlocked) \ + lumiera_lock_section_ = { \ + cnd, (lumiera_sectionlock_unlock_fn) lumiera_reccondition_unlock \ + NOBUG_ALPHA_COMMA(&NOBUG_FLAG(nobugflag)) NOBUG_ALPHA_COMMA_NULL}; \ + ({ \ + if (lumiera_lock_section_.lock) \ + lumiera_lock_section_.lock = \ + lumiera_reccondition_lock (cnd, &NOBUG_FLAG(nobugflag), \ + &lumiera_lock_section_.rh, NOBUG_CONTEXT); \ + lumiera_lock_section_.lock; \ + }); \ + ({ \ + LUMIERA_RECCONDITION_SECTION_UNLOCK; \ })) -#define LUMIERA_RECCONDITION_SECTION_CHAIN(nobugflag, cnd) \ - for (lumiera_sectionlock *lumiera_lock_section_old_ = &lumiera_lock_section_, \ - NOBUG_CLEANUP(lumiera_sectionlock_ensureunlocked) lumiera_lock_section_ = { \ - cnd, (lumiera_sectionlock_unlock_fn) lumiera_reccondition_unlock \ - NOBUG_ALPHA_COMMA(&NOBUG_FLAG(nobugflag)) NOBUG_ALPHA_COMMA_NULL}; \ - ({ \ - if (lumiera_lock_section_.lock) \ - { \ - REQUIRE (lumiera_lock_section_old_->lock, "section prematurely unlocked"); \ - lumiera_lock_section_.lock = \ - lumiera_reccondition_lock (cnd, &NOBUG_FLAG(nobugflag), &lumiera_lock_section_.rh); \ - LUMIERA_SECTION_UNLOCK_(lumiera_lock_section_old_); \ - } \ - lumiera_lock_section_.lock; \ - }); \ - ({ \ - LUMIERA_RECCONDITION_SECTION_UNLOCK; \ +#define LUMIERA_RECCONDITION_SECTION_CHAIN(nobugflag, cnd) \ + for (lumiera_sectionlock *lumiera_lock_section_old_ = &lumiera_lock_section_, \ + NOBUG_CLEANUP(lumiera_sectionlock_ensureunlocked) lumiera_lock_section_ = { \ + cnd, (lumiera_sectionlock_unlock_fn) lumiera_reccondition_unlock \ + NOBUG_ALPHA_COMMA(&NOBUG_FLAG(nobugflag)) NOBUG_ALPHA_COMMA_NULL}; \ + ({ \ + if (lumiera_lock_section_.lock) \ + { \ + REQUIRE (lumiera_lock_section_old_->lock, "section prematurely unlocked"); \ + lumiera_lock_section_.lock = \ + lumiera_reccondition_lock (cnd, &NOBUG_FLAG(nobugflag), \ + &lumiera_lock_section_.rh, NOBUG_CONTEXT); \ + LUMIERA_SECTION_UNLOCK_(lumiera_lock_section_old_); \ + } \ + lumiera_lock_section_.lock; \ + }); \ + ({ \ + LUMIERA_RECCONDITION_SECTION_UNLOCK; \ })) @@ -95,7 +97,8 @@ REQUIRE (lumiera_lock_section_.lock, "Reccondition mutex not locked"); \ lumiera_reccondition_wait (lumiera_lock_section_.lock, \ lumiera_lock_section_.flag, \ - &lumiera_lock_section_.rh); \ + &lumiera_lock_section_.rh, \ + NOBUG_CONTEXT); \ } while (!(expr)) @@ -112,7 +115,8 @@ if (!lumiera_reccondition_timedwait (lumiera_lock_section_.lock, \ timeout, \ lumiera_lock_section_.flag, \ - &lumiera_lock_section_.rh)) \ + &lumiera_lock_section_.rh, \ + NOBUG_CONTEXT)) \ break; \ } while (!(expr)) @@ -128,7 +132,8 @@ do { \ REQUIRE (lumiera_lock_section_.lock, "Reccondition mutex not locked"); \ lumiera_reccondition_signal (lumiera_lock_section_.lock, \ - lumiera_lock_section_.flag); \ + lumiera_lock_section_.flag, \ + NOBUG_CONTEXT); \ } while (0) @@ -141,7 +146,8 @@ do { \ REQUIRE (lumiera_lock_section_.lock, "Reccondition mutex not locked"); \ lumiera_reccondition_broadcast (lumiera_lock_section_.lock, \ - lumiera_lock_section_.flag); \ + lumiera_lock_section_.flag, \ + NOBUG_CONTEXT); \ } while (0) @@ -165,7 +171,10 @@ typedef lumiera_reccondition* LumieraReccondition; * @return self as given */ LumieraReccondition -lumiera_reccondition_init (LumieraReccondition self, const char* purpose, struct nobug_flag* flag); +lumiera_reccondition_init (LumieraReccondition self, + const char* purpose, + struct nobug_flag* flag, + const struct nobug_context ctx); /** @@ -174,21 +183,26 @@ lumiera_reccondition_init (LumieraReccondition self, const char* purpose, struct * @return self as given */ LumieraReccondition -lumiera_reccondition_destroy (LumieraReccondition self, struct nobug_flag* flag); +lumiera_reccondition_destroy (LumieraReccondition self, + struct nobug_flag* flag, + const struct nobug_context ctx); static inline LumieraReccondition -lumiera_reccondition_lock (LumieraReccondition self, struct nobug_flag* flag, struct nobug_resource_user** handle) +lumiera_reccondition_lock (LumieraReccondition self, + struct nobug_flag* flag, + struct nobug_resource_user** handle, + const struct nobug_context ctx) { if (self) { - RESOURCE_WAIT (NOBUG_FLAG_RAW(flag), self->rh, "acquire reccondvar", *handle); + NOBUG_RESOURCE_WAIT_CTX (NOBUG_FLAG_RAW(flag), self->rh, "acquire reccondvar", *handle, ctx); if (pthread_mutex_lock (&self->reccndmutex)) LUMIERA_DIE (LOCK_ACQUIRE); /* never reached (in a correct program) */ - RESOURCE_STATE (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_RECURSIVE, *handle); + NOBUG_RESOURCE_STATE_CTX (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_RECURSIVE, *handle, ctx); } return self; @@ -196,22 +210,25 @@ lumiera_reccondition_lock (LumieraReccondition self, struct nobug_flag* flag, st static inline LumieraReccondition -lumiera_reccondition_trylock (LumieraReccondition self, struct nobug_flag* flag, struct nobug_resource_user** handle) +lumiera_reccondition_trylock (LumieraReccondition self, + struct nobug_flag* flag, + struct nobug_resource_user** handle, + const struct nobug_context ctx) { if (self) { - NOBUG_RESOURCE_TRY (NOBUG_FLAG_RAW(flag), self->rh, "try acquire reccondvar", *handle); + NOBUG_RESOURCE_TRY_CTX (NOBUG_FLAG_RAW(flag), self->rh, "try acquire reccondvar", *handle, ctx); int err = pthread_mutex_trylock (&self->reccndmutex); if (!err) { - RESOURCE_STATE (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_RECURSIVE, *handle); + NOBUG_RESOURCE_STATE_CTX (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_RECURSIVE, *handle, ctx); } else { - NOBUG_RESOURCE_LEAVE_RAW(flag, *handle) /*{}*/; - lumiera_lockerror_set (err, flag, __func__); + NOBUG_RESOURCE_LEAVE_RAW_CTX (flag, *handle, ctx) /*{}*/; + lumiera_lockerror_set (err, flag, ctx); return NULL; } } @@ -224,22 +241,23 @@ static inline LumieraReccondition lumiera_reccondition_timedlock (LumieraReccondition self, const struct timespec* timeout, struct nobug_flag* flag, - struct nobug_resource_user** handle) + struct nobug_resource_user** handle, + const struct nobug_context ctx) { if (self) { - NOBUG_RESOURCE_TRY (NOBUG_FLAG_RAW(flag), self->rh, "timed acquire reccondvar", *handle); + NOBUG_RESOURCE_TRY_CTX (NOBUG_FLAG_RAW(flag), self->rh, "timed acquire reccondvar", *handle, ctx); int err = pthread_mutex_timedlock (&self->reccndmutex, timeout); if (!err) { - RESOURCE_STATE (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_RECURSIVE, *handle); + NOBUG_RESOURCE_STATE_CTX (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_RECURSIVE, *handle, ctx); } else { - NOBUG_RESOURCE_LEAVE_RAW(flag, *handle) /*{}*/; - lumiera_lockerror_set (err, flag, __func__); + NOBUG_RESOURCE_LEAVE_RAW_CTX (flag, *handle, ctx) /*{}*/; + lumiera_lockerror_set (err, flag, ctx); return NULL; } } @@ -249,15 +267,18 @@ lumiera_reccondition_timedlock (LumieraReccondition self, static inline LumieraReccondition -lumiera_reccondition_wait (LumieraReccondition self, struct nobug_flag* flag, struct nobug_resource_user** handle) +lumiera_reccondition_wait (LumieraReccondition self, + struct nobug_flag* flag, + struct nobug_resource_user** handle, + const struct nobug_context ctx) { if (self) { - NOBUG_RESOURCE_STATE_RAW (flag, NOBUG_RESOURCE_WAITING, *handle); + NOBUG_RESOURCE_STATE_RAW_CTX (flag, NOBUG_RESOURCE_WAITING, *handle, ctx); pthread_cond_wait (&self->cond, &self->reccndmutex); - NOBUG_RESOURCE_STATE_RAW (flag, NOBUG_RESOURCE_RECURSIVE, *handle); + NOBUG_RESOURCE_STATE_RAW_CTX (flag, NOBUG_RESOURCE_RECURSIVE, *handle, ctx); } return self; } @@ -267,22 +288,23 @@ static inline LumieraReccondition lumiera_reccondition_timedwait (LumieraReccondition self, const struct timespec* timeout, struct nobug_flag* flag, - struct nobug_resource_user** handle) + struct nobug_resource_user** handle, + const struct nobug_context ctx) { if (self) { - NOBUG_RESOURCE_STATE_RAW (flag, NOBUG_RESOURCE_WAITING, *handle); + NOBUG_RESOURCE_STATE_RAW_CTX (flag, NOBUG_RESOURCE_WAITING, *handle, ctx); int err; do { err = pthread_cond_timedwait (&self->cond, &self->reccndmutex, timeout); } while(err == EINTR); - NOBUG_RESOURCE_STATE_RAW (flag, NOBUG_RESOURCE_RECURSIVE, *handle); + NOBUG_RESOURCE_STATE_RAW_CTX (flag, NOBUG_RESOURCE_RECURSIVE, *handle, ctx); if (err) { - lumiera_lockerror_set (err, flag, __func__); + lumiera_lockerror_set (err, flag, ctx); return NULL; } } @@ -293,27 +315,34 @@ lumiera_reccondition_timedwait (LumieraReccondition self, static inline void -lumiera_reccondition_signal (LumieraReccondition self, struct nobug_flag* flag) +lumiera_reccondition_signal (LumieraReccondition self, + struct nobug_flag* flag, + const struct nobug_context ctx) { - TRACE(NOBUG_FLAG_RAW(flag), "Signal %p", self); + NOBUG_TRACE_CTX (NOBUG_FLAG_RAW (flag), ctx, "Signal %p", self); pthread_cond_signal (&self->cond); } static inline void -lumiera_reccondition_broadcast (LumieraReccondition self, struct nobug_flag* flag) +lumiera_reccondition_broadcast (LumieraReccondition self, + struct nobug_flag* flag, + const struct nobug_context ctx) { - TRACE(NOBUG_FLAG_RAW(flag), "Broadcast %p", self); + NOBUG_TRACE_CTX (NOBUG_FLAG_RAW(flag), ctx, "Broadcast %p", self); pthread_cond_broadcast (&self->cond); } static inline void -lumiera_reccondition_unlock (LumieraReccondition self, struct nobug_flag* flag, struct nobug_resource_user** handle) +lumiera_reccondition_unlock (LumieraReccondition self, + struct nobug_flag* flag, + struct nobug_resource_user** handle, + const struct nobug_context ctx) { - REQUIRE(self); + NOBUG_REQUIRE_CTX (self, ctx); - NOBUG_RESOURCE_LEAVE_RAW(flag, *handle) + NOBUG_RESOURCE_LEAVE_RAW_CTX (flag, *handle, ctx) { if (pthread_mutex_unlock (&self->reccndmutex)) LUMIERA_DIE (LOCK_RELEASE); /* never reached (in a correct program) */ diff --git a/src/lib/recmutex.c b/src/lib/recmutex.c index f2a609ac2..7a852c2a1 100644 --- a/src/lib/recmutex.c +++ b/src/lib/recmutex.c @@ -38,7 +38,10 @@ static void recmutexattr_init() LumieraRecmutex -lumiera_recmutex_init (LumieraRecmutex self, const char* purpose, struct nobug_flag* flag) +lumiera_recmutex_init (LumieraRecmutex self, + const char* purpose, + struct nobug_flag* flag, + const struct nobug_context ctx) { if (self) { @@ -46,7 +49,7 @@ lumiera_recmutex_init (LumieraRecmutex self, const char* purpose, struct nobug_f pthread_mutex_init (&self->recmutex, &recmutexattr); NOBUG_RESOURCE_HANDLE_INIT (self->rh); - NOBUG_RESOURCE_ANNOUNCE_RAW (flag, "recmutex", purpose, self, self->rh); + NOBUG_RESOURCE_ANNOUNCE_RAW_CTX (flag, "recmutex", purpose, self, self->rh, ctx); } return self; @@ -54,11 +57,13 @@ lumiera_recmutex_init (LumieraRecmutex self, const char* purpose, struct nobug_f LumieraRecmutex -lumiera_recmutex_destroy (LumieraRecmutex self, struct nobug_flag* flag) +lumiera_recmutex_destroy (LumieraRecmutex self, + struct nobug_flag* flag, + const struct nobug_context ctx) { if (self) { - NOBUG_RESOURCE_FORGET_RAW (flag, self->rh); + NOBUG_RESOURCE_FORGET_RAW_CTX (flag, self->rh, ctx); if (pthread_mutex_destroy (&self->recmutex)) LUMIERA_DIE (LOCK_DESTROY); } diff --git a/src/lib/recmutex.h b/src/lib/recmutex.h index 9754e56b1..8383e6210 100644 --- a/src/lib/recmutex.h +++ b/src/lib/recmutex.h @@ -38,39 +38,41 @@ /** * Recursive Mutual exclusive section. */ -#define LUMIERA_RECMUTEX_SECTION(nobugflag, mtx) \ - for (lumiera_sectionlock NOBUG_CLEANUP(lumiera_sectionlock_ensureunlocked) \ - lumiera_lock_section_ = { \ - mtx, (lumiera_sectionlock_unlock_fn) lumiera_mutex_unlock \ - NOBUG_ALPHA_COMMA(&NOBUG_FLAG(nobugflag)) NOBUG_ALPHA_COMMA_NULL}; \ - ({ \ - if (lumiera_lock_section_.lock) \ - lumiera_lock_section_.lock = \ - lumiera_recmutex_lock (mtx, &NOBUG_FLAG(nobugflag), &lumiera_lock_section_.rh); \ - lumiera_lock_section_.lock; \ - }); \ - ({ \ - LUMIERA_RECMUTEX_SECTION_UNLOCK; \ +#define LUMIERA_RECMUTEX_SECTION(nobugflag, mtx) \ + for (lumiera_sectionlock NOBUG_CLEANUP(lumiera_sectionlock_ensureunlocked) \ + lumiera_lock_section_ = { \ + mtx, (lumiera_sectionlock_unlock_fn) lumiera_mutex_unlock \ + NOBUG_ALPHA_COMMA(&NOBUG_FLAG(nobugflag)) NOBUG_ALPHA_COMMA_NULL}; \ + ({ \ + if (lumiera_lock_section_.lock) \ + lumiera_lock_section_.lock = \ + lumiera_recmutex_lock (mtx, &NOBUG_FLAG(nobugflag), \ + &lumiera_lock_section_.rh, NOBUG_CONTEXT); \ + lumiera_lock_section_.lock; \ + }); \ + ({ \ + LUMIERA_RECMUTEX_SECTION_UNLOCK; \ })) -#define LUMIERA_RECMUTEX_SECTION_CHAIN(nobugflag, mtx) \ - for (lumiera_sectionlock *lumiera_lock_section_old_ = &lumiera_lock_section_, \ - NOBUG_CLEANUP(lumiera_sectionlock_ensureunlocked) lumiera_lock_section_ = { \ - mtx, (lumiera_sectionlock_unlock_fn) lumiera_mutex_unlock \ - NOBUG_ALPHA_COMMA(&NOBUG_FLAG(nobugflag)) NOBUG_ALPHA_COMMA_NULL}; \ - ({ \ - if (lumiera_lock_section_.lock) \ - { \ - REQUIRE (lumiera_lock_section_old_->lock, "section prematurely unlocked"); \ - lumiera_lock_section_.lock = \ - lumiera_recmutex_lock (mtx, &NOBUG_FLAG(nobugflag), lumiera_lock_section_.rh); \ - LUMIERA_SECTION_UNLOCK_(lumiera_lock_section_old_); \ - } \ - lumiera_lock_section_.lock; \ - }); \ - ({ \ - LUMIERA_RECMUTEX_SECTION_UNLOCK; \ +#define LUMIERA_RECMUTEX_SECTION_CHAIN(nobugflag, mtx) \ + for (lumiera_sectionlock *lumiera_lock_section_old_ = &lumiera_lock_section_, \ + NOBUG_CLEANUP(lumiera_sectionlock_ensureunlocked) lumiera_lock_section_ = { \ + mtx, (lumiera_sectionlock_unlock_fn) lumiera_mutex_unlock \ + NOBUG_ALPHA_COMMA(&NOBUG_FLAG(nobugflag)) NOBUG_ALPHA_COMMA_NULL}; \ + ({ \ + if (lumiera_lock_section_.lock) \ + { \ + REQUIRE (lumiera_lock_section_old_->lock, "section prematurely unlocked"); \ + lumiera_lock_section_.lock = \ + lumiera_recmutex_lock (mtx, &NOBUG_FLAG(nobugflag), \ + lumiera_lock_section_.rh, NOBUG_CONTEXT); \ + LUMIERA_SECTION_UNLOCK_(lumiera_lock_section_old_); \ + } \ + lumiera_lock_section_.lock; \ + }); \ + ({ \ + LUMIERA_RECMUTEX_SECTION_UNLOCK; \ })) @@ -98,7 +100,10 @@ typedef lumiera_recmutex* LumieraRecmutex; * @return self as given */ LumieraRecmutex -lumiera_recmutex_init (LumieraRecmutex self, const char* purpose, struct nobug_flag* flag); +lumiera_recmutex_init (LumieraRecmutex self, + const char* purpose, + struct nobug_flag* flag, + const struct nobug_context ctx); /** * Destroy a recursive mutex variable @@ -106,20 +111,25 @@ lumiera_recmutex_init (LumieraRecmutex self, const char* purpose, struct nobug_f * @return self as given */ LumieraRecmutex -lumiera_recmutex_destroy (LumieraRecmutex self, struct nobug_flag* flag); +lumiera_recmutex_destroy (LumieraRecmutex self, + struct nobug_flag* flag, + const struct nobug_context ctx); static inline LumieraRecmutex -lumiera_recmutex_lock (LumieraRecmutex self, struct nobug_flag* flag, struct nobug_resource_user** handle) +lumiera_recmutex_lock (LumieraRecmutex self, + struct nobug_flag* flag, + struct nobug_resource_user** handle, + const struct nobug_context ctx) { if (self) { - RESOURCE_WAIT (NOBUG_FLAG_RAW(flag), self->rh, "acquire mutex", *handle); + NOBUG_RESOURCE_WAIT_CTX (NOBUG_FLAG_RAW(flag), self->rh, "acquire mutex", *handle, ctx); if (pthread_mutex_lock (&self->recmutex)) LUMIERA_DIE (LOCK_ACQUIRE); /* never reached (in a correct program) */ - RESOURCE_STATE (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_RECURSIVE, *handle); + NOBUG_RESOURCE_STATE_CTX (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_RECURSIVE, *handle, ctx); } return self; @@ -127,22 +137,25 @@ lumiera_recmutex_lock (LumieraRecmutex self, struct nobug_flag* flag, struct nob static inline LumieraRecmutex -lumiera_recmutex_trylock (LumieraRecmutex self, struct nobug_flag* flag, struct nobug_resource_user** handle) +lumiera_recmutex_trylock (LumieraRecmutex self, + struct nobug_flag* flag, + struct nobug_resource_user** handle, + const struct nobug_context ctx) { if (self) { - NOBUG_RESOURCE_TRY (NOBUG_FLAG_RAW(flag), self->rh, "try acquire mutex", *handle); + NOBUG_RESOURCE_TRY_CTX (NOBUG_FLAG_RAW(flag), self->rh, "try acquire mutex", *handle, ctx); int err = pthread_mutex_trylock (&self->recmutex); if (!err) { - RESOURCE_STATE (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_RECURSIVE, *handle); + NOBUG_RESOURCE_STATE_CTX (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_RECURSIVE, *handle, ctx); } else { - NOBUG_RESOURCE_LEAVE_RAW(flag, *handle) /*{}*/; - lumiera_lockerror_set (err, flag, __func__); + NOBUG_RESOURCE_LEAVE_RAW_CTX (flag, *handle, ctx) /*{}*/; + lumiera_lockerror_set (err, flag, ctx); return NULL; } } @@ -155,22 +168,23 @@ static inline LumieraRecmutex lumiera_recmutex_timedlock (LumieraRecmutex self, const struct timespec* timeout, struct nobug_flag* flag, - struct nobug_resource_user** handle) + struct nobug_resource_user** handle, + const struct nobug_context ctx) { if (self) { - NOBUG_RESOURCE_TRY (NOBUG_FLAG_RAW(flag), self->rh, "timed acquire mutex", *handle); + NOBUG_RESOURCE_TRY_CTX (NOBUG_FLAG_RAW(flag), self->rh, "timed acquire mutex", *handle, ctx); int err = pthread_mutex_timedlock (&self->recmutex, timeout); if (!err) { - RESOURCE_STATE (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_RECURSIVE, *handle); + NOBUG_RESOURCE_STATE_CTX (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_RECURSIVE, *handle, ctx); } else { - NOBUG_RESOURCE_LEAVE_RAW(flag, *handle) /*{}*/; - lumiera_lockerror_set (err, flag, __func__); + NOBUG_RESOURCE_LEAVE_RAW_CTX (flag, *handle, ctx) /*{}*/; + lumiera_lockerror_set (err, flag, ctx); return NULL; } } @@ -180,11 +194,14 @@ lumiera_recmutex_timedlock (LumieraRecmutex self, static inline void -lumiera_recmutex_unlock (LumieraRecmutex self, struct nobug_flag* flag, struct nobug_resource_user** handle) +lumiera_recmutex_unlock (LumieraRecmutex self, + struct nobug_flag* flag, + struct nobug_resource_user** handle, + const struct nobug_context ctx) { - REQUIRE (self); + NOBUG_REQUIRE_CTX (self, ctx); - NOBUG_RESOURCE_LEAVE_RAW(flag, *handle) + NOBUG_RESOURCE_LEAVE_RAW_CTX (flag, *handle, ctx) { if (pthread_mutex_unlock (&self->recmutex)) LUMIERA_DIE (LOCK_RELEASE); /* never reached (in a correct program) */ diff --git a/src/lib/resourcecollector.c b/src/lib/resourcecollector.c index 1919c853f..4ce58eaa0 100644 --- a/src/lib/resourcecollector.c +++ b/src/lib/resourcecollector.c @@ -51,7 +51,7 @@ lumiera_resourcecollector_init_ (void) for (int i = 0; i < LUMIERA_RESOURCE_END; ++i) llist_init (&lumiera_resourcecollector_registry[i]); - lumiera_mutex_init (&lumiera_resourcecollector_lock, "resourcecollector", &NOBUG_FLAG(mutex_dbg)); + lumiera_mutex_init (&lumiera_resourcecollector_lock, "resourcecollector", &NOBUG_FLAG(mutex_dbg), NOBUG_CONTEXT); } @@ -65,7 +65,7 @@ lumiera_resourcecollector_destroy (void) LLIST_WHILE_HEAD (&lumiera_resourcecollector_registry[i], head) lumiera_resourcehandler_unregister ((LumieraResourcehandler)head); - lumiera_mutex_destroy (&lumiera_resourcecollector_lock, &NOBUG_FLAG(mutex_dbg)); + lumiera_mutex_destroy (&lumiera_resourcecollector_lock, &NOBUG_FLAG(mutex_dbg), NOBUG_CONTEXT); } diff --git a/src/lib/rwlock.c b/src/lib/rwlock.c index a62774696..349af6dff 100644 --- a/src/lib/rwlock.c +++ b/src/lib/rwlock.c @@ -29,24 +29,29 @@ */ LumieraRWLock -lumiera_rwlock_init (LumieraRWLock self, const char* purpose, struct nobug_flag* flag) +lumiera_rwlock_init (LumieraRWLock self, + const char* purpose, + struct nobug_flag* flag, + const struct nobug_context ctx) { if (self) { pthread_rwlock_init (&self->rwlock, NULL); NOBUG_RESOURCE_HANDLE_INIT (self->rh); - NOBUG_RESOURCE_ANNOUNCE_RAW (flag, "rwlock", purpose, self, self->rh); + NOBUG_RESOURCE_ANNOUNCE_RAW_CTX (flag, "rwlock", purpose, self, self->rh, ctx); } return self; } LumieraRWLock -lumiera_rwlock_destroy (LumieraRWLock self, struct nobug_flag* flag) +lumiera_rwlock_destroy (LumieraRWLock self, + struct nobug_flag* flag, + const struct nobug_context ctx) { if (self) { - NOBUG_RESOURCE_FORGET_RAW (flag, self->rh); + NOBUG_RESOURCE_FORGET_RAW_CTX (flag, self->rh, ctx); if (pthread_rwlock_destroy (&self->rwlock)) LUMIERA_DIE (LOCK_DESTROY); } diff --git a/src/lib/rwlock.h b/src/lib/rwlock.h index a059f3767..f651f7b24 100644 --- a/src/lib/rwlock.h +++ b/src/lib/rwlock.h @@ -44,39 +44,41 @@ * Read locked section. * readlocks may fail when there are too much readers, one has to check the error afterwards! */ -#define LUMIERA_RDLOCK_SECTION(nobugflag, rwlck) \ - for (lumiera_sectionlock NOBUG_CLEANUP(lumiera_sectionlock_ensureunlocked) \ - lumiera_lock_section_ = { \ - rwlck, (lumiera_sectionlock_unlock_fn) lumiera_rwlock_unlock \ - NOBUG_ALPHA_COMMA(&NOBUG_FLAG(nobugflag)) NOBUG_ALPHA_COMMA_NULL}; \ - ({ \ - if (lumiera_lock_section_.lock) \ - lumiera_lock_section_.lock = \ - lumiera_rwlock_rdlock (rwlck, &NOBUG_FLAG(nobugflag), &lumiera_lock_section_.rh); \ - lumiera_lock_section_.lock; \ - }); \ - ({ \ - LUMIERA_RWLOCK_SECTION_UNLOCK; \ +#define LUMIERA_RDLOCK_SECTION(nobugflag, rwlck) \ + for (lumiera_sectionlock NOBUG_CLEANUP(lumiera_sectionlock_ensureunlocked) \ + lumiera_lock_section_ = { \ + rwlck, (lumiera_sectionlock_unlock_fn) lumiera_rwlock_unlock \ + NOBUG_ALPHA_COMMA(&NOBUG_FLAG(nobugflag)) NOBUG_ALPHA_COMMA_NULL}; \ + ({ \ + if (lumiera_lock_section_.lock) \ + lumiera_lock_section_.lock = \ + lumiera_rwlock_rdlock (rwlck, &NOBUG_FLAG(nobugflag), \ + &lumiera_lock_section_.rh, NOBUG_CONTEXT); \ + lumiera_lock_section_.lock; \ + }); \ + ({ \ + LUMIERA_RWLOCK_SECTION_UNLOCK; \ })) -#define LUMIERA_RDLOCK_SECTION_CHAIN(nobugflag, rwlck) \ - for (lumiera_sectionlock *lumiera_lock_section_old_ = &lumiera_lock_section_, \ - NOBUG_CLEANUP(lumiera_sectionlock_ensureunlocked) lumiera_lock_section_ = { \ - rwlck, (lumiera_sectionlock_unlock_fn) lumiera_rwlock_unlock \ - NOBUG_ALPHA_COMMA(&NOBUG_FLAG(nobugflag)) NOBUG_ALPHA_COMMA_NULL}; \ - ({ \ - if (lumiera_lock_section_.lock) \ - { \ - REQUIRE (lumiera_lock_section_old_->lock, "section prematurely unlocked"); \ - lumiera_lock_section_.lock = \ - lumiera_rwlock_rdlock (rwlck, &NOBUG_FLAG(nobugflag), lumiera_lock_section_.rh); \ - LUMIERA_SECTION_UNLOCK_(lumiera_lock_section_old_); \ - } \ - lumiera_lock_section_.lock; \ - }); \ - ({ \ - LUMIERA_RWLOCK_SECTION_UNLOCK; \ +#define LUMIERA_RDLOCK_SECTION_CHAIN(nobugflag, rwlck) \ + for (lumiera_sectionlock *lumiera_lock_section_old_ = &lumiera_lock_section_, \ + NOBUG_CLEANUP(lumiera_sectionlock_ensureunlocked) lumiera_lock_section_ = { \ + rwlck, (lumiera_sectionlock_unlock_fn) lumiera_rwlock_unlock \ + NOBUG_ALPHA_COMMA(&NOBUG_FLAG(nobugflag)) NOBUG_ALPHA_COMMA_NULL}; \ + ({ \ + if (lumiera_lock_section_.lock) \ + { \ + REQUIRE (lumiera_lock_section_old_->lock, "section prematurely unlocked"); \ + lumiera_lock_section_.lock = \ + lumiera_rwlock_rdlock (rwlck, &NOBUG_FLAG(nobugflag), \ + lumiera_lock_section_.rh, NOBUG_CONTEXT); \ + LUMIERA_SECTION_UNLOCK_(lumiera_lock_section_old_); \ + } \ + lumiera_lock_section_.lock; \ + }); \ + ({ \ + LUMIERA_RWLOCK_SECTION_UNLOCK; \ })) @@ -84,39 +86,41 @@ /** * Write locked section. */ -#define LUMIERA_WRLOCK_SECTION(nobugflag, rwlck) \ - for (lumiera_sectionlock NOBUG_CLEANUP(lumiera_sectionlock_ensureunlocked) \ - lumiera_lock_section_ = { \ - rwlck, (lumiera_sectionlock_unlock_fn) lumiera_rwlock_unlock \ - NOBUG_ALPHA_COMMA(&NOBUG_FLAG(nobugflag)) NOBUG_ALPHA_COMMA_NULL}; \ - ({ \ - if (lumiera_lock_section_.lock) \ - lumiera_lock_section_.lock = \ - lumiera_rwlock_wrlock (rwlck, &NOBUG_FLAG(nobugflag), &lumiera_lock_section_.rh); \ - lumiera_lock_section_.lock; \ - }); \ - ({ \ - LUMIERA_RWLOCK_SECTION_UNLOCK; \ +#define LUMIERA_WRLOCK_SECTION(nobugflag, rwlck) \ + for (lumiera_sectionlock NOBUG_CLEANUP(lumiera_sectionlock_ensureunlocked) \ + lumiera_lock_section_ = { \ + rwlck, (lumiera_sectionlock_unlock_fn) lumiera_rwlock_unlock \ + NOBUG_ALPHA_COMMA(&NOBUG_FLAG(nobugflag)) NOBUG_ALPHA_COMMA_NULL}; \ + ({ \ + if (lumiera_lock_section_.lock) \ + lumiera_lock_section_.lock = \ + lumiera_rwlock_wrlock (rwlck, &NOBUG_FLAG(nobugflag), \ + &lumiera_lock_section_.rh, NOBUG_CONTEXT); \ + lumiera_lock_section_.lock; \ + }); \ + ({ \ + LUMIERA_RWLOCK_SECTION_UNLOCK; \ })) -#define LUMIERA_WRLOCK_SECTION_CHAIN(nobugflag, rwlck) \ - for (lumiera_sectionlock *lumiera_lock_section_old_ = &lumiera_lock_section_, \ - NOBUG_CLEANUP(lumiera_sectionlock_ensureunlocked) lumiera_lock_section_ = { \ - rwlck, (lumiera_sectionlock_unlock_fn) lumiera_rwlock_unlock \ - NOBUG_ALPHA_COMMA(&NOBUG_FLAG(nobugflag)) NOBUG_ALPHA_COMMA_NULL}; \ - ({ \ - if (lumiera_lock_section_.lock) \ - { \ - REQUIRE (lumiera_lock_section_old_->lock, "section prematurely unlocked"); \ - lumiera_lock_section_.lock = \ - lumiera_rwlock_wrlock (rwlck, &NOBUG_FLAG(nobugflag), lumiera_lock_section_.rh); \ - LUMIERA_SECTION_UNLOCK_(lumiera_lock_section_old_); \ - } \ - lumiera_lock_section_.lock; \ - }); \ - ({ \ - LUMIERA_RWLOCK_SECTION_UNLOCK; \ +#define LUMIERA_WRLOCK_SECTION_CHAIN(nobugflag, rwlck) \ + for (lumiera_sectionlock *lumiera_lock_section_old_ = &lumiera_lock_section_, \ + NOBUG_CLEANUP(lumiera_sectionlock_ensureunlocked) lumiera_lock_section_ = { \ + rwlck, (lumiera_sectionlock_unlock_fn) lumiera_rwlock_unlock \ + NOBUG_ALPHA_COMMA(&NOBUG_FLAG(nobugflag)) NOBUG_ALPHA_COMMA_NULL}; \ + ({ \ + if (lumiera_lock_section_.lock) \ + { \ + REQUIRE (lumiera_lock_section_old_->lock, "section prematurely unlocked"); \ + lumiera_lock_section_.lock = \ + lumiera_rwlock_wrlock (rwlck, &NOBUG_FLAG(nobugflag), \ + lumiera_lock_section_.rh, NOBUG_CONTEXT); \ + LUMIERA_SECTION_UNLOCK_(lumiera_lock_section_old_); \ + } \ + lumiera_lock_section_.lock; \ + }); \ + ({ \ + LUMIERA_RWLOCK_SECTION_UNLOCK; \ })) @@ -142,7 +146,10 @@ typedef lumiera_rwlock* LumieraRWLock; * @return self as given */ LumieraRWLock -lumiera_rwlock_init (LumieraRWLock self, const char* purpose, struct nobug_flag* flag); +lumiera_rwlock_init (LumieraRWLock self, + const char* purpose, + struct nobug_flag* flag, + const struct nobug_context ctx); /** * destroy a rwlock @@ -150,25 +157,31 @@ lumiera_rwlock_init (LumieraRWLock self, const char* purpose, struct nobug_flag* * @return self on success or NULL at error */ LumieraRWLock -lumiera_rwlock_destroy (LumieraRWLock self, struct nobug_flag* flag); +lumiera_rwlock_destroy (LumieraRWLock self, + struct nobug_flag* flag, + const struct nobug_context ctx); + static inline LumieraRWLock -lumiera_rwlock_rdlock (LumieraRWLock self, struct nobug_flag* flag, struct nobug_resource_user** handle) +lumiera_rwlock_rdlock (LumieraRWLock self, + struct nobug_flag* flag, + struct nobug_resource_user** handle, + const struct nobug_context ctx) { if (self) { - RESOURCE_WAIT (NOBUG_FLAG_RAW(flag), self->rh, "acquire rwlock for reading", *handle); + NOBUG_RESOURCE_WAIT_CTX (NOBUG_FLAG_RAW(flag), self->rh, "acquire rwlock for reading", *handle, ctx); int err = pthread_rwlock_rdlock (&self->rwlock); if (!err) { - RESOURCE_STATE (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_SHARED, *handle); + NOBUG_RESOURCE_STATE_CTX (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_SHARED, *handle, ctx); } else { - NOBUG_RESOURCE_LEAVE_RAW(flag, *handle) /*{}*/; - lumiera_lockerror_set (err, flag, __func__); + NOBUG_RESOURCE_LEAVE_RAW_CTX (flag, *handle, ctx) /*{}*/; + lumiera_lockerror_set (err, flag, ctx); return NULL; } } @@ -178,22 +191,25 @@ lumiera_rwlock_rdlock (LumieraRWLock self, struct nobug_flag* flag, struct nobug static inline LumieraRWLock -lumiera_rwlock_tryrdlock (LumieraRWLock self, struct nobug_flag* flag, struct nobug_resource_user** handle) +lumiera_rwlock_tryrdlock (LumieraRWLock self, + struct nobug_flag* flag, + struct nobug_resource_user** handle, + const struct nobug_context ctx) { if (self) { - NOBUG_RESOURCE_TRY (NOBUG_FLAG_RAW(flag), self->rh, "try acquire rwlock for reading", *handle); + NOBUG_RESOURCE_TRY_CTX (NOBUG_FLAG_RAW(flag), self->rh, "try acquire rwlock for reading", *handle, ctx); int err = pthread_rwlock_tryrdlock (&self->rwlock); if (!err) { - RESOURCE_STATE (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_SHARED, *handle); + NOBUG_RESOURCE_STATE_CTX (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_SHARED, *handle, ctx); } else { - NOBUG_RESOURCE_LEAVE_RAW(flag, *handle) /*{}*/; - lumiera_lockerror_set (err, flag, __func__); + NOBUG_RESOURCE_LEAVE_RAW_CTX (flag, *handle, ctx) /*{}*/; + lumiera_lockerror_set (err, flag, ctx); return NULL; } } @@ -206,22 +222,23 @@ static inline LumieraRWLock lumiera_rwlock_timedrdlock (LumieraRWLock self, const struct timespec* timeout, struct nobug_flag* flag, - struct nobug_resource_user** handle) + struct nobug_resource_user** handle, + const struct nobug_context ctx) { if (self) { - NOBUG_RESOURCE_TRY (NOBUG_FLAG_RAW(flag), self->rh, "timed acquire rwlock for reading", *handle); + NOBUG_RESOURCE_TRY_CTX (NOBUG_FLAG_RAW(flag), self->rh, "timed acquire rwlock for reading", *handle, ctx); int err = pthread_rwlock_timedrdlock (&self->rwlock, timeout); if (!err) { - RESOURCE_STATE (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_SHARED, *handle); + NOBUG_RESOURCE_STATE_CTX (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_SHARED, *handle, ctx); } else { - NOBUG_RESOURCE_LEAVE_RAW(flag, *handle) /*{}*/; - lumiera_lockerror_set (err, flag, __func__); + NOBUG_RESOURCE_LEAVE_RAW_CTX (flag, *handle, ctx) /*{}*/; + lumiera_lockerror_set (err, flag, ctx); return NULL; } } @@ -231,16 +248,19 @@ lumiera_rwlock_timedrdlock (LumieraRWLock self, static inline LumieraRWLock -lumiera_rwlock_wrlock (LumieraRWLock self, struct nobug_flag* flag, struct nobug_resource_user** handle) +lumiera_rwlock_wrlock (LumieraRWLock self, + struct nobug_flag* flag, + struct nobug_resource_user** handle, + const struct nobug_context ctx) { if (self) { - RESOURCE_WAIT (NOBUG_FLAG_RAW(flag), self->rh, "acquire rwlock for writing", *handle); + NOBUG_RESOURCE_WAIT_CTX (NOBUG_FLAG_RAW(flag), self->rh, "acquire rwlock for writing", *handle, ctx); if (pthread_rwlock_wrlock (&self->rwlock)) LUMIERA_DIE (LOCK_ACQUIRE); /* never reached (in a correct program) */ - RESOURCE_STATE (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_EXCLUSIVE, *handle); + NOBUG_RESOURCE_STATE_CTX (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_EXCLUSIVE, *handle, ctx); } return self; @@ -248,22 +268,25 @@ lumiera_rwlock_wrlock (LumieraRWLock self, struct nobug_flag* flag, struct nobug static inline LumieraRWLock -lumiera_rwlock_trywrlock (LumieraRWLock self, struct nobug_flag* flag, struct nobug_resource_user** handle) +lumiera_rwlock_trywrlock (LumieraRWLock self, + struct nobug_flag* flag, + struct nobug_resource_user** handle, + const struct nobug_context ctx) { if (self) { - NOBUG_RESOURCE_TRY (NOBUG_FLAG_RAW(flag), self->rh, "try acquire rwlock for writing", *handle); + NOBUG_RESOURCE_TRY_CTX (NOBUG_FLAG_RAW(flag), self->rh, "try acquire rwlock for writing", *handle, ctx); int err = pthread_rwlock_trywrlock (&self->rwlock); if (!err) { - RESOURCE_STATE (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_EXCLUSIVE, *handle); + NOBUG_RESOURCE_STATE_CTX (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_EXCLUSIVE, *handle, ctx); } else { - NOBUG_RESOURCE_LEAVE_RAW(flag, *handle) /*{}*/; - lumiera_lockerror_set (err, flag, __func__); + NOBUG_RESOURCE_LEAVE_RAW_CTX (flag, *handle, ctx) /*{}*/; + lumiera_lockerror_set (err, flag, ctx); return NULL; } } @@ -276,22 +299,23 @@ static inline LumieraRWLock lumiera_rwlock_timedwrlock (LumieraRWLock self, const struct timespec* timeout, struct nobug_flag* flag, - struct nobug_resource_user** handle) + struct nobug_resource_user** handle, + const struct nobug_context ctx) { if (self) { - NOBUG_RESOURCE_TRY (NOBUG_FLAG_RAW(flag), self->rh, "timed acquire rwlock for writing", *handle); + NOBUG_RESOURCE_TRY_CTX (NOBUG_FLAG_RAW(flag), self->rh, "timed acquire rwlock for writing", *handle, ctx); int err = pthread_rwlock_timedwrlock (&self->rwlock, timeout); if (!err) { - RESOURCE_STATE (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_EXCLUSIVE, *handle); + NOBUG_RESOURCE_STATE_CTX (NOBUG_FLAG_RAW(flag), NOBUG_RESOURCE_EXCLUSIVE, *handle, ctx); } else { - NOBUG_RESOURCE_LEAVE_RAW(flag, *handle) /*{}*/; - lumiera_lockerror_set (err, flag, __func__); + NOBUG_RESOURCE_LEAVE_RAW_CTX (flag, *handle, ctx) /*{}*/; + lumiera_lockerror_set (err, flag, ctx); return NULL; } } @@ -301,11 +325,14 @@ lumiera_rwlock_timedwrlock (LumieraRWLock self, static inline void -lumiera_rwlock_unlock (LumieraRWLock self, struct nobug_flag* flag, struct nobug_resource_user** handle) +lumiera_rwlock_unlock (LumieraRWLock self, + struct nobug_flag* flag, + struct nobug_resource_user** handle, + const struct nobug_context ctx) { - REQUIRE(self); + NOBUG_REQUIRE_CTX (self, ctx); - NOBUG_RESOURCE_LEAVE_RAW(flag, *handle) + NOBUG_RESOURCE_LEAVE_RAW_CTX (flag, *handle, ctx) { if (pthread_rwlock_unlock (&self->rwlock)) LUMIERA_DIE (LOCK_RELEASE); /* never reached (in a correct program) */ diff --git a/src/lib/sectionlock.h b/src/lib/sectionlock.h index a0a751ce7..61225e84b 100644 --- a/src/lib/sectionlock.h +++ b/src/lib/sectionlock.h @@ -26,7 +26,10 @@ #include -typedef int (*lumiera_sectionlock_unlock_fn)(void*, struct nobug_flag* flag, struct nobug_resource_user** handle); +typedef int +(*lumiera_sectionlock_unlock_fn)(void*, struct nobug_flag* flag, + struct nobug_resource_user** handle, + const struct nobug_context ctx); /** * sectionlock used to manage the state of mutexes. @@ -55,11 +58,12 @@ lumiera_sectionlock_ensureunlocked (LumieraSectionlock self) * @param sectionname name used for the sectionlock instance * @param ... some extra code to execute */ -#define LUMIERA_SECTION_UNLOCK_(section) \ - do if ((section)->lock) \ - { \ - (section)->unlock((section)->lock, (section)->flag, &(section)->rh); \ - (section)->lock = NULL; \ +#define LUMIERA_SECTION_UNLOCK_(section) \ + do if ((section)->lock) \ + { \ + (section)->unlock((section)->lock, (section)->flag, \ + &(section)->rh, NOBUG_CONTEXT); \ + (section)->lock = NULL; \ } while (0) diff --git a/src/lib/sync.hpp b/src/lib/sync.hpp index 6cd0cd294..f877f4246 100644 --- a/src/lib/sync.hpp +++ b/src/lib/sync.hpp @@ -97,27 +97,31 @@ namespace lib { lumiera_mutex self; protected: - Wrapped_LumieraExcMutex() { lumiera_mutex_init (&self, "Obj.Monitor ExclMutex", &NOBUG_FLAG(sync)); } - ~Wrapped_LumieraExcMutex() { lumiera_mutex_destroy (&self, &NOBUG_FLAG(sync)); } + Wrapped_LumieraExcMutex(const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC) + { lumiera_mutex_init (&self, "Obj.Monitor ExclMutex", &NOBUG_FLAG(sync), ctx); } + ~Wrapped_LumieraExcMutex() + { lumiera_mutex_destroy (&self, &NOBUG_FLAG(sync), NOBUG_CONTEXT); } - bool lock (struct nobug_resource_user** handle) + bool lock (struct nobug_resource_user** handle, const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC) { - return !!lumiera_mutex_lock (&self, &NOBUG_FLAG(sync), handle); + return !!lumiera_mutex_lock (&self, &NOBUG_FLAG(sync), handle, ctx); } - bool trylock (struct nobug_resource_user** handle) + bool trylock (struct nobug_resource_user** handle, const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC) { - return !!lumiera_mutex_trylock (&self, &NOBUG_FLAG(sync), handle); + return !!lumiera_mutex_trylock (&self, &NOBUG_FLAG(sync), handle, ctx); } - bool timedlock (const struct timespec* timeout, struct nobug_resource_user** handle) + bool timedlock (const struct timespec* timeout, + struct nobug_resource_user** handle, + const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC) { - return !!lumiera_mutex_timedlock (&self, timeout, &NOBUG_FLAG(sync), handle); + return !!lumiera_mutex_timedlock (&self, timeout, &NOBUG_FLAG(sync), handle, ctx); } - void unlock (struct nobug_resource_user** handle) + void unlock (struct nobug_resource_user** handle, const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC) { - lumiera_mutex_unlock (&self, &NOBUG_FLAG(sync), handle); + lumiera_mutex_unlock (&self, &NOBUG_FLAG(sync), handle, ctx); } LumieraReccondition myreccond () {throw "bullshit"; return NULL;} // placeholder, brainstorm @@ -128,27 +132,32 @@ namespace lib { { lumiera_recmutex self; protected: - Wrapped_LumieraRecMutex() { lumiera_recmutex_init (&self, "Obj.Monitor RecMutex", &NOBUG_FLAG(sync)); } - ~Wrapped_LumieraRecMutex() { lumiera_recmutex_destroy (&self, &NOBUG_FLAG(sync)); } + Wrapped_LumieraRecMutex(const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC) + { lumiera_recmutex_init (&self, "Obj.Monitor RecMutex", &NOBUG_FLAG(sync), ctx); } + ~Wrapped_LumieraRecMutex() + { lumiera_recmutex_destroy (&self, &NOBUG_FLAG(sync), NOBUG_CONTEXT); } - bool lock (struct nobug_resource_user** handle) + bool lock (struct nobug_resource_user** handle, const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC) { - return !!lumiera_recmutex_lock (&self, &NOBUG_FLAG(sync), handle); + return !!lumiera_recmutex_lock (&self, &NOBUG_FLAG(sync), handle, ctx); } - bool trylock (struct nobug_resource_user** handle) + bool trylock (struct nobug_resource_user** handle, const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC) { - return !!lumiera_recmutex_trylock (&self, &NOBUG_FLAG(sync), handle); + return !!lumiera_recmutex_trylock (&self, &NOBUG_FLAG(sync), handle, ctx); } - bool timedlock (const struct timespec* timeout, struct nobug_resource_user** handle) + bool timedlock (const struct timespec* timeout, + struct nobug_resource_user** handle, + const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC) { - return !!lumiera_recmutex_timedlock (&self, timeout, &NOBUG_FLAG(sync), handle); + return !!lumiera_recmutex_timedlock (&self, timeout, &NOBUG_FLAG(sync), handle, ctx); } - void unlock (struct nobug_resource_user** handle) + void unlock (struct nobug_resource_user** handle, + const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC) { - lumiera_recmutex_unlock (&self, &NOBUG_FLAG(sync), handle); + lumiera_recmutex_unlock (&self, &NOBUG_FLAG(sync), handle, ctx); } LumieraReccondition myreccond () {throw "bullshit"; return NULL;} // placeholder, brainstorm @@ -159,47 +168,53 @@ namespace lib { { lumiera_condition self; protected: - Wrapped_LumieraExcCond() { lumiera_condition_init (&self, "Obj.Monitor ExclCondition", &NOBUG_FLAG(sync) ); } - ~Wrapped_LumieraExcCond() { lumiera_condition_destroy (&self, &NOBUG_FLAG(sync) ); } + Wrapped_LumieraExcCond(const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC) + { lumiera_condition_init (&self, "Obj.Monitor ExclCondition", &NOBUG_FLAG(sync), ctx); } + ~Wrapped_LumieraExcCond() + { lumiera_condition_destroy (&self, &NOBUG_FLAG(sync), NOBUG_CONTEXT); } - bool lock (struct nobug_resource_user** handle) + bool lock (struct nobug_resource_user** handle, const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC) { - return !!lumiera_condition_lock (&self, &NOBUG_FLAG(sync), handle); + return !!lumiera_condition_lock (&self, &NOBUG_FLAG(sync), handle, ctx); } - bool trylock (struct nobug_resource_user** handle) + bool trylock (struct nobug_resource_user** handle, const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC) { - return !!lumiera_condition_trylock (&self, &NOBUG_FLAG(sync), handle); + return !!lumiera_condition_trylock (&self, &NOBUG_FLAG(sync), handle, ctx); } - bool timedlock (const struct timespec* timeout, struct nobug_resource_user** handle) + bool timedlock (const struct timespec* timeout, + struct nobug_resource_user** handle, + const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC) { - return !!lumiera_condition_timedlock (&self, timeout, &NOBUG_FLAG(sync), handle); + return !!lumiera_condition_timedlock (&self, timeout, &NOBUG_FLAG(sync), handle, ctx); } - bool wait (struct nobug_resource_user** handle) + bool wait (struct nobug_resource_user** handle, const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC) { - return !!lumiera_condition_wait (&self, &NOBUG_FLAG(sync), handle); + return !!lumiera_condition_wait (&self, &NOBUG_FLAG(sync), handle, ctx); } - bool timedwait (const struct timespec* timeout, struct nobug_resource_user** handle) + bool timedwait (const struct timespec* timeout, + struct nobug_resource_user** handle, + const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC) { - return !!lumiera_condition_timedwait (&self, timeout, &NOBUG_FLAG(sync), handle); + return !!lumiera_condition_timedwait (&self, timeout, &NOBUG_FLAG(sync), handle, ctx); } - void signal() + void signal(const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC) { - lumiera_condition_signal (&self, &NOBUG_FLAG(sync)); + lumiera_condition_signal (&self, &NOBUG_FLAG(sync), ctx); } - void broadcast() + void broadcast(const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC) { - lumiera_condition_broadcast (&self, &NOBUG_FLAG(sync)); + lumiera_condition_broadcast (&self, &NOBUG_FLAG(sync), ctx); } - void unlock (struct nobug_resource_user** handle) + void unlock (struct nobug_resource_user** handle, const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC) { - lumiera_condition_unlock (&self, &NOBUG_FLAG(sync), handle); + lumiera_condition_unlock (&self, &NOBUG_FLAG(sync), handle, ctx); } LumieraReccondition myreccond () {throw "bullshit"; return NULL;} // placeholder, brainstorm @@ -210,47 +225,53 @@ namespace lib { { lumiera_reccondition self; protected: - Wrapped_LumieraRecCond() { lumiera_reccondition_init (&self, "Obj.Monitor RecCondition", &NOBUG_FLAG(sync) ); } - ~Wrapped_LumieraRecCond() { lumiera_reccondition_destroy (&self, &NOBUG_FLAG(sync) ); } + Wrapped_LumieraRecCond(const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC) + { lumiera_reccondition_init (&self, "Obj.Monitor RecCondition", &NOBUG_FLAG(sync), ctx); } + ~Wrapped_LumieraRecCond() + { lumiera_reccondition_destroy (&self, &NOBUG_FLAG(sync), NOBUG_CONTEXT); } - bool lock (struct nobug_resource_user** handle) + bool lock (struct nobug_resource_user** handle, const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC) { - return !!lumiera_reccondition_lock (&self, &NOBUG_FLAG(sync), handle); + return !!lumiera_reccondition_lock (&self, &NOBUG_FLAG(sync), handle, ctx); } - bool trylock (struct nobug_resource_user** handle) + bool trylock (struct nobug_resource_user** handle, const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC) { - return !!lumiera_reccondition_trylock (&self, &NOBUG_FLAG(sync), handle); + return !!lumiera_reccondition_trylock (&self, &NOBUG_FLAG(sync), handle, ctx); } - bool timedlock (const struct timespec* timeout, struct nobug_resource_user** handle) + bool timedlock (const struct timespec* timeout, + struct nobug_resource_user** handle, + const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC) { - return !!lumiera_reccondition_timedlock (&self, timeout, &NOBUG_FLAG(sync), handle); + return !!lumiera_reccondition_timedlock (&self, timeout, &NOBUG_FLAG(sync), handle, ctx); } - bool wait (struct nobug_resource_user** handle) + bool wait (struct nobug_resource_user** handle, const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC) { - return !!lumiera_reccondition_wait (&self, &NOBUG_FLAG(sync), handle); + return !!lumiera_reccondition_wait (&self, &NOBUG_FLAG(sync), handle, ctx); } - bool timedwait (const struct timespec* timeout, struct nobug_resource_user** handle) + bool timedwait (const struct timespec* timeout, + struct nobug_resource_user** handle, + const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC) { - return !!lumiera_reccondition_timedwait (&self, timeout, &NOBUG_FLAG(sync), handle); + return !!lumiera_reccondition_timedwait (&self, timeout, &NOBUG_FLAG(sync), handle, ctx); } - void signal() + void signal(const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC) { - lumiera_reccondition_signal (&self, &NOBUG_FLAG(sync)); + lumiera_reccondition_signal (&self, &NOBUG_FLAG(sync), ctx); } - void broadcast() + void broadcast(const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC) { - lumiera_reccondition_broadcast (&self, &NOBUG_FLAG(sync)); + lumiera_reccondition_broadcast (&self, &NOBUG_FLAG(sync), ctx); } - void unlock (struct nobug_resource_user** handle) + void unlock (struct nobug_resource_user** handle, const struct nobug_context ctx = NOBUG_CONTEXT_NOFUNC) { - lumiera_reccondition_unlock (&self, &NOBUG_FLAG(sync), handle); + lumiera_reccondition_unlock (&self, &NOBUG_FLAG(sync), handle, ctx); } LumieraReccondition myreccond () { return &self;} // placeholder, brainstorm diff --git a/tests/backend/test-threads.c b/tests/backend/test-threads.c index 14237f7a2..180fd5496 100644 --- a/tests/backend/test-threads.c +++ b/tests/backend/test-threads.c @@ -103,7 +103,7 @@ TEST ("simple_thread") TEST ("thread_synced") { lumiera_reccondition cnd; - lumiera_reccondition_init (&cnd, "threadsync", &NOBUG_FLAG(NOBUG_ON)); + lumiera_reccondition_init (&cnd, "threadsync", &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); LUMIERA_RECCONDITION_SECTION(cond_sync, &cnd) { @@ -127,14 +127,14 @@ TEST ("thread_synced") ECHO ("thread ended %s", NOBUG_THREAD_ID_GET); } - lumiera_reccondition_destroy (&cnd, &NOBUG_FLAG(NOBUG_ON)); + lumiera_reccondition_destroy (&cnd, &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); } TEST ("mutex_thread") { - lumiera_mutex_init (&testmutex, "test", &NOBUG_FLAG(NOBUG_ON)); + lumiera_mutex_init (&testmutex, "test", &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); LUMIERA_MUTEX_SECTION (NOBUG_ON, &testmutex) { @@ -152,7 +152,7 @@ TEST ("mutex_thread") fprintf (stderr, "main after thread %s\n", NOBUG_THREAD_ID_GET); } - lumiera_mutex_destroy (&testmutex, &NOBUG_FLAG(NOBUG_ON)); + lumiera_mutex_destroy (&testmutex, &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); } diff --git a/tests/library/test-locking.c b/tests/library/test-locking.c index 14ec0c458..7c4903aab 100644 --- a/tests/library/test-locking.c +++ b/tests/library/test-locking.c @@ -35,7 +35,7 @@ TESTS_BEGIN TEST ("mutexsection") { lumiera_mutex m; - lumiera_mutex_init (&m, "mutexsection", &NOBUG_FLAG(NOBUG_ON)); + lumiera_mutex_init (&m, "mutexsection", &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); LUMIERA_MUTEX_SECTION (NOBUG_ON, &m) { @@ -47,28 +47,28 @@ TEST ("mutexsection") printf ("mutex locked section 2\n"); } - lumiera_mutex_destroy (&m, &NOBUG_FLAG(NOBUG_ON)); + lumiera_mutex_destroy (&m, &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); } TEST ("mutexforgotunlock") { lumiera_mutex m; - lumiera_mutex_init (&m, "mutexforgotunlock", &NOBUG_FLAG(NOBUG_ON)); + lumiera_mutex_init (&m, "mutexforgotunlock", &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); LUMIERA_MUTEX_SECTION (NOBUG_ON, &m) { break; // MUTEX_SECTIONS must not be left by a jump } - lumiera_mutex_destroy (&m, &NOBUG_FLAG(NOBUG_ON)); + lumiera_mutex_destroy (&m, &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); } TEST ("mutexexplicitunlock") { lumiera_mutex m; - lumiera_mutex_init (&m, "mutexforgotunlock", &NOBUG_FLAG(NOBUG_ON)); + lumiera_mutex_init (&m, "mutexforgotunlock", &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); LUMIERA_MUTEX_SECTION (NOBUG_ON, &m) { @@ -77,17 +77,17 @@ TEST ("mutexexplicitunlock") break; } - lumiera_mutex_destroy (&m, &NOBUG_FLAG(NOBUG_ON)); + lumiera_mutex_destroy (&m, &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); } TEST ("nestedmutexsection") { lumiera_mutex m; - lumiera_mutex_init (&m, "m_mutexsection", &NOBUG_FLAG(NOBUG_ON)); + lumiera_mutex_init (&m, "m_mutexsection", &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); lumiera_mutex n; - lumiera_mutex_init (&n, "n_mutexsection", &NOBUG_FLAG(NOBUG_ON)); + lumiera_mutex_init (&n, "n_mutexsection", &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); LUMIERA_MUTEX_SECTION (NOBUG_ON, &m) { @@ -99,17 +99,17 @@ TEST ("nestedmutexsection") } } - lumiera_mutex_destroy (&n, &NOBUG_FLAG(NOBUG_ON)); - lumiera_mutex_destroy (&m, &NOBUG_FLAG(NOBUG_ON)); + lumiera_mutex_destroy (&n, &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); + lumiera_mutex_destroy (&m, &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); } TEST ("chainedmutexsection") { lumiera_mutex m; - lumiera_mutex_init (&m, "m_mutexsection", &NOBUG_FLAG(NOBUG_ON)); + lumiera_mutex_init (&m, "m_mutexsection", &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); lumiera_mutex n; - lumiera_mutex_init (&n, "n_mutexsection", &NOBUG_FLAG(NOBUG_ON)); + lumiera_mutex_init (&n, "n_mutexsection", &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); LUMIERA_MUTEX_SECTION (NOBUG_ON, &m) { @@ -121,8 +121,8 @@ TEST ("chainedmutexsection") } } - lumiera_mutex_destroy (&n, &NOBUG_FLAG(NOBUG_ON)); - lumiera_mutex_destroy (&m, &NOBUG_FLAG(NOBUG_ON)); + lumiera_mutex_destroy (&n, &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); + lumiera_mutex_destroy (&m, &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); } @@ -130,7 +130,7 @@ TEST ("chainedmutexsection") TEST ("recursivemutexsection") { lumiera_recmutex m; - lumiera_recmutex_init (&m, "m_recmutexsection", &NOBUG_FLAG(NOBUG_ON)); + lumiera_recmutex_init (&m, "m_recmutexsection", &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); LUMIERA_RECMUTEX_SECTION (NOBUG_ON, &m) @@ -143,7 +143,7 @@ TEST ("recursivemutexsection") } } - lumiera_recmutex_destroy (&m, &NOBUG_FLAG(NOBUG_ON)); + lumiera_recmutex_destroy (&m, &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); } @@ -151,7 +151,7 @@ TEST ("recursivemutexsection") TEST ("rwlocksection") { lumiera_rwlock rwlock; - lumiera_rwlock_init (&rwlock, "rwsection", &NOBUG_FLAG(NOBUG_ON)); + lumiera_rwlock_init (&rwlock, "rwsection", &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); LUMIERA_WRLOCK_SECTION (NOBUG_ON, &rwlock) { @@ -163,21 +163,21 @@ TEST ("rwlocksection") printf ("read locked section 2\n"); } - lumiera_rwlock_destroy (&rwlock, &NOBUG_FLAG(NOBUG_ON)); + lumiera_rwlock_destroy (&rwlock, &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); } TEST ("rwlockforgotunlock") { lumiera_rwlock rwlock; - lumiera_rwlock_init (&rwlock, "rwlockforgotunlock", &NOBUG_FLAG(NOBUG_ON)); + lumiera_rwlock_init (&rwlock, "rwlockforgotunlock", &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); LUMIERA_RDLOCK_SECTION (NOBUG_ON, &rwlock) { break; // LOCK_SECTIONS must not be left by a jump } - lumiera_rwlock_destroy (&rwlock, &NOBUG_FLAG(NOBUG_ON)); + lumiera_rwlock_destroy (&rwlock, &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); } @@ -185,7 +185,7 @@ TEST ("rwlockforgotunlock") TEST ("rwdeadlockwr") { lumiera_rwlock rwlock; - lumiera_rwlock_init (&rwlock, "rwsection", &NOBUG_FLAG(NOBUG_ON)); + lumiera_rwlock_init (&rwlock, "rwsection", &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); LUMIERA_WRLOCK_SECTION (NOBUG_ON, &rwlock) { @@ -196,7 +196,7 @@ TEST ("rwdeadlockwr") } } - lumiera_rwlock_destroy (&rwlock, &NOBUG_FLAG(NOBUG_ON)); + lumiera_rwlock_destroy (&rwlock, &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); } @@ -204,7 +204,7 @@ TEST ("rwdeadlockwr") TEST ("rwdeadlockrw") { lumiera_rwlock rwlock; - lumiera_rwlock_init (&rwlock, "rwsection", &NOBUG_FLAG(NOBUG_ON)); + lumiera_rwlock_init (&rwlock, "rwsection", &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); LUMIERA_RDLOCK_SECTION (NOBUG_ON, &rwlock) { @@ -215,14 +215,14 @@ TEST ("rwdeadlockrw") } } - lumiera_rwlock_destroy (&rwlock, &NOBUG_FLAG(NOBUG_ON)); + lumiera_rwlock_destroy (&rwlock, &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); } TEST ("conditionops (compiletest only)") { lumiera_condition cond; - lumiera_condition_init (&cond, "conditionsection", &NOBUG_FLAG(NOBUG_ON)); + lumiera_condition_init (&cond, "conditionsection", &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); LUMIERA_CONDITION_SECTION (NOBUG_ON, &cond) { @@ -231,14 +231,14 @@ TEST ("conditionops (compiletest only)") LUMIERA_CONDITION_BROADCAST; } - lumiera_condition_destroy (&cond, &NOBUG_FLAG(NOBUG_ON)); + lumiera_condition_destroy (&cond, &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); } TEST ("conditionsection") { lumiera_condition cond; - lumiera_condition_init (&cond, "conditionsection", &NOBUG_FLAG(NOBUG_ON)); + lumiera_condition_init (&cond, "conditionsection", &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); LUMIERA_CONDITION_SECTION (NOBUG_ON, &cond) { @@ -250,7 +250,7 @@ TEST ("conditionsection") printf ("condition locked section 2\n"); } - lumiera_condition_destroy (&cond, &NOBUG_FLAG(NOBUG_ON)); + lumiera_condition_destroy (&cond, &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); } @@ -258,14 +258,14 @@ TEST ("conditionsection") TEST ("conditionforgotunlock") { lumiera_condition cond; - lumiera_condition_init (&cond, "conditionforgotunlock", &NOBUG_FLAG(NOBUG_ON)); + lumiera_condition_init (&cond, "conditionforgotunlock", &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); LUMIERA_CONDITION_SECTION (NOBUG_ON, &cond) { break; // CONDITION_SECTIONS must not be left by a jump } - lumiera_condition_destroy (&cond, &NOBUG_FLAG(NOBUG_ON)); + lumiera_condition_destroy (&cond, &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); } @@ -273,7 +273,7 @@ TEST ("conditionforgotunlock") TEST ("recconditionops (compiletest only)") { lumiera_reccondition reccond; - lumiera_reccondition_init (&reccond, "recconditionsection", &NOBUG_FLAG(NOBUG_ON)); + lumiera_reccondition_init (&reccond, "recconditionsection", &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); LUMIERA_RECCONDITION_SECTION (NOBUG_ON, &reccond) { @@ -282,14 +282,14 @@ TEST ("recconditionops (compiletest only)") LUMIERA_RECCONDITION_BROADCAST; } - lumiera_reccondition_destroy (&reccond, &NOBUG_FLAG(NOBUG_ON)); + lumiera_reccondition_destroy (&reccond, &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); } TEST ("recconditionsection") { lumiera_reccondition reccond; - lumiera_reccondition_init (&reccond, "recconditionsection", &NOBUG_FLAG(NOBUG_ON)); + lumiera_reccondition_init (&reccond, "recconditionsection", &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); LUMIERA_RECCONDITION_SECTION (NOBUG_ON, &reccond) { @@ -301,21 +301,21 @@ TEST ("recconditionsection") printf ("reccondition locked section 2\n"); } - lumiera_reccondition_destroy (&reccond, &NOBUG_FLAG(NOBUG_ON)); + lumiera_reccondition_destroy (&reccond, &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); } TEST ("recconditionforgotunlock") { lumiera_reccondition reccond; - lumiera_reccondition_init (&reccond, "recconditionforgotunlock", &NOBUG_FLAG(NOBUG_ON)); + lumiera_reccondition_init (&reccond, "recconditionforgotunlock", &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); LUMIERA_RECCONDITION_SECTION (NOBUG_ON, &reccond) { break; // RECCONDITION_SECTIONS must not be left by a jump } - lumiera_reccondition_destroy (&reccond, &NOBUG_FLAG(NOBUG_ON)); + lumiera_reccondition_destroy (&reccond, &NOBUG_FLAG(NOBUG_ON), NOBUG_CONTEXT); }