- To: ecos-discuss@xxxxxxxxxxxxxxxxxxx
- Subject: Using mutex.owner to detect re-entry
- From: Tom Schouten <tom@xxxxxxxxx>
- Date: Tue, 10 Apr 2012 19:27:58 +0200
- Comment: DKIM? See http://www.dkim.org
- Comment: DomainKeys? See http://antispam.yahoo.com/domainkeys
- User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.17) Gecko/20110510 Icedove/3.1.10
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
[Linux Embedded]
[U-Boot V2]
[Linux Kernel]
[Linux MIPS]
[Linux ARM]
[Linux for the Blind]
[Linux Resources]
[Photo]
[Yosemite]
[ISDN Cause Codes]
[ECOS Home]
[Site Home]