#include <cthreads.h>
#include <hurd/hurd_types.h>
#define RECURSIVE_LOCK_INITIALIZER = {0, 0, MUTEX_INITIALIZER};
struct recursive_lock
{
spin_lock_t protection;
int locked;
struct mutex mutex;
};
void recursive_lock (struct recursive_lock *lock);
void recursive_unlock (struct recursive_lock *lock);
void
recursive_lock (struct recursive_lock *lock)
{
spin_lock (&lock->protection);
if (lock->locked)
{
lock->locked++;
spin_unlock (&lock->protection);
}
else
{
spin_unlock (&lock->protection);
mutex_lock (&lock->mutex) spin_lock (&lock->protection);
lock->locked = 1;
spin_unlock (&lock->protection);
}
}
void
recursive_unlock (struct recursive_lock *lock)
{
spin_lock (&lock->protection);
if (!lock->locked)
{
spin_unlock (&lock->protection);
return;
}
lock->locked--;
if (!lock->locked)
mutex_unlock (&lock->mutex) spin_unlock (&lock->protection);
}
_______________________________________________
Bug-hurd mailing list
[EMAIL PROTECTED]
http://mail.gnu.org/mailman/listinfo/bug-hurd