[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
a recursive lock prototype
From: |
moshez |
Subject: |
a recursive lock prototype |
Date: |
Thu, 5 Jul 2001 02:47:58 +0200 (CEST) |
#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);
}
- a recursive lock prototype,
moshez <=
- Re: a recursive lock prototype, Thomas Bushnell, BSG, 2001/07/04
- Re: a recursive lock prototype, Niels Möller, 2001/07/05
- Re: a recursive lock prototype, Marcus Brinkmann, 2001/07/05
- Re: a recursive lock prototype, Thomas Bushnell, BSG, 2001/07/05
- Re: a recursive lock prototype, Marcus Brinkmann, 2001/07/06
- Re: a recursive lock prototype, Thomas Bushnell, BSG, 2001/07/06
- Re: a recursive lock prototype, Marcus Brinkmann, 2001/07/07
- Re: a recursive lock prototype, Thomas Bushnell, BSG, 2001/07/08
- Re: a recursive lock prototype, Marcus Brinkmann, 2001/07/09