When using the pthreads recursive mutex, the level method was only able
to return either zero or one, but a recursive mutex can be locked more
than once.
Additionally, the way this detected if the mutex was already locked was
to test whether it can be locked again. If testing from the thread that
is currently holding the lock, this locking attempt always succeeds, and
therefore determines that the lock is _not_ held at all. This is
especially bad, as this operation only makes sense to perform from the
thread that holds the lock -- if any thread not holding the lock queries
the number of times the lock is held, that answer can change before the
thread can used it.
Signed-off-by: Bobby Bingham <koorogi@koorogi.info>
Thread ID is opaque type pthread_t, it may not be compatible with integer,
and may integer with valid id `0`.
Change to store mutex owner thread ID as `pthread_t` type with valid flag
and compare with `pthread_equal()`,
and don't try to print it.
Signed-off-by: OBATA Akio <obache@wizdas.com>