[ECOS] reentrant mutex
Nick Garnett
nickg@ecoscentric.com
Mon Apr 14 12:02:00 GMT 2003
Jonathan Larmour <jifl@eCosCentric.com> writes:
> mark_lee_hamilton@att.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
More information about the Ecos-discuss
mailing list