[En-Nut-Discussion] Mutex Implementation anybody?

Matthias Ringwald mringwal at inf.ethz.ch
Fri Apr 16 16:26:20 CEST 2004


Hi Harald,

thanks for answering.


> It's a simple mutual exclusion semaphore only.
>
> Init: NutEventPost
> Lock: NutEventWait
> Release: NutEventPost
> Destroy: Not required, because a queue needs almost no space.
Sure.


> It works, because Nut/OS sets the queue to SIGNALED,
> if an event is posted to an empty queue.
>
> If someone wants to have something more versatile,
> I'm open to this idea.
I'm not sure, if I will need a recursive mutex
but as it is simple to implement one (using one extra int for counting)
I would choose to do so. (so one thread could lock one mutex several 
times)

>  I'd only ask for, to limit the
> usage of such more versatile functions in the kernel
> code. Please do not replace existing code just because
> it looks fancy.
I completely agree with this.

My arguments, why I would write and add a mutex.c|h implementation
to os/ are:

- to me, the semantics of a mutex and the queue are quite different
(althoug a queue can be used to implement a mutex). as for me,
mutex is about object locking and queues are about signaling other 
threads.
- I will implement a recursive mutex (new functionality)
- it would use the nut/os queue, thus the implementation is clean and 
simple.
- And... as it is a single file and it is not used by any other kenel 
functions,
its code would not be linked in unless it is called.

Convinced... :)

matthias




More information about the En-Nut-Discussion mailing list