[En-Nut-Discussion] Feature Request 1572837: mutex API nesting level info

Nathan Moore nategoose at gmail.com
Mon Jul 14 17:09:33 CEST 2008


>
> If you already protect the function with a mutex, you're save to use a
> simple
> int counter as your own locking count inside the function. Then you
> neither
> have to access internals of the mutex nor have to use "exotic" :) APIs.
>
> I think the idea of the recursive mutexes is that you don't need to worry
about if a mutex will be locked 'again' by a lower level function, so
keeping a counter makes the user need to be more aware of when a lower level
would do this, and edit the lower level code to also count.
Personally I haven't needed this value returned, but I can see how it may be
very useful to find errors.  Just using the count as a boolean at the
application level would be enough for simple testing, though:
    unsigned rc;
    ...
    rc = NutMutexLock(&lock);
    ...
    assert (NutMutexUnlock(&lock)==(rc-1) );
(or similar) could be useful anywhere, if there weren't the NutMutexTryLock
that returns a value already.

Not changing away from posix-like only matters if you are trying to achieve
posix compatability, which itn't likely to a large degree within NutOs.
Also, it's just a value that can be ignored if you don't use it.

Nathan



More information about the En-Nut-Discussion mailing list