This is the mail archive of the
ecos-discuss@sources.redhat.com
mailing list for the eCos project.
Re: reentrant mutex
- From: Nick Garnett <nickg at ecoscentric dot com>
- To: Jonathan Larmour <jifl at eCosCentric dot com>
- Cc: mark_lee_hamilton at att dot net, ecos <ecos-discuss at sources dot redhat dot com>
- Date: 14 Apr 2003 10:50:21 +0100
- Subject: Re: [ECOS] reentrant mutex
- References: <20030411230531.DB402383F7@jifvik.dyndns.org><3E977529.3000804@eCosCentric.com>
Jonathan Larmour <jifl at eCosCentric dot com> writes:
> mark_lee_hamilton at att dot net wrote:
> > Will reentrant mutex support be added in the near future? I ask
> > because this functionality is currently missing in 2.0 beta. I
> > scanned through the email archives and noticed that topic was
> > brought up a while back. There didn't seem to be much of a desire to
> > support a reentrant mutex. I'm hoping that there has been a change
> > of heart on the topic.
>
> I think it's unlikely we'd want to make existing mutexes recursive,
> but as indeed one of the threads in the past mentioned, some separate
> recursive mutex type could be added.
>
> Whether or not "strategically" such a patch would be accepted in the
> sources I'll leave to Nick G though. Personally I'm keen as the kernel
> is meant to be more than just basic primitives, but a box of tools to
> make development easier.
>
I would personally not like to see such a patch. It would not work
very well with condition variables and any system that mixed regular
and recursive mutexes would be very hard to debug.
In my opinion, a need for recursive mutexes is usually a symptom of
poor program design.
If anybody really wants recursive mutexes, then they can always
implement them above the existing mutex mechanism. For example:
typedef struct
{
cyg_mutex_t mutex;
cyg_handle_t owner;
cyg_uint32 count;
} cyg_recursive_mutex;
void cyg_recursive_mutex_lock( cyg_recursive_mutex *mx )
{
cyg_scheduler_lock();
{
if( cyg_thread_self() == mx->owner )
{
mx->count++;
}
else
{
cyg_mutex_lock( &mx->mutex );
mx->count = 1;
mx->owner = cyg_thread_self();
}
}
cyg_scheduler_unlock();
}
The rest is left as an exercise for the reader.
--
Nick Garnett eCos Kernel Architect
http://www.ecoscentric.com/ The eCos and RedBoot experts
--
Before posting, please read the FAQ: http://sources.redhat.com/fom/ecos
and search the list archive: http://sources.redhat.com/ml/ecos-discuss