* [ECOS] Using mutex.owner to detect re-entry
@ 2012-04-10 17:28 Tom Schouten
0 siblings, 0 replies; only message in thread
From: Tom Schouten @ 2012-04-10 17:28 UTC (permalink / raw)
To: ecos-discuss
Hi List,
Is it safe to use the following approach to use a mutex to detect re-entry?
( i.e. to avoid thread-local variables to keep an entry counter.)
static int re_entry(cyg_mutext_t *m) {
return (m->owner == (void*)cyg_thread_self());
}
As used in the following fragment:
cyg_mutex_t m;
int some_call() {
if (re_entry(&m)) {
/* Break off recursion. */
return error_re_entry;
}
else {
cyg_mutex_lock(&m);
int err = re_entry_protected_call(); /* Might call some_call(),
which should then return error_re_entry */
cyg_mutex_unlock(&);
return err;
}
}
Rationale: This is safe because (see mutex.cpp)
- If it's not self it's either NULL or the value of another thread, but
if this is the case it can never become self due to a race condition.
I.e. we're sure this is not a re-entrant call
- It's self if and only if it's a re-entrant call.
Cheers,
Tom
--
Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos
and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2012-04-10 17:28 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-10 17:28 [ECOS] Using mutex.owner to detect re-entry Tom Schouten
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).