Re: recursive locks in kernel?

SK (sushil@cse.iitk.ac.in)
Sat, 25 Sep 1999 11:23:05 +0530 (IST)


There is a small mistake in get_recursive_lock(). I have rectified it and
reposting the function. We don't need to lock r->data_to_lock
(r->data_to_lock = 1) inside the if(atomic ...) because it was done by the
atomic_test_and_set.

Also still there could be some race conditions because we are not locking
the structure r itself while manipulating its fields (owner_id and
lock_count) but these will be harmless. Infact we cannot lock the
structure r because then it will not be recursive because the lower level
function will block while trying to lock the structure resulting in a
deadlock.

get_recursive_lock(recursive_lock_t *r)
{
if(atomic_test_and_set(&r->data_to_lock) == 0) { /* if lock is free */

/* RECTIFICATION : following line is not required */
/*r->data_to_lock = 1; */ /* lock it */

r->owner_pid = current->pid; /* make ourself as the owner */
r->lock_count = 1; /* first instance of this lock */
return;
}

...
(rest same as before)
}

Counting semaphores (with down(&sem) and up(&sem) primitives) cannot be
used to have recursive locks because first this is a blocking lock, and
second with sem->count the recursion will be limited.

Kindly correct me whereever i am wrong.

- Sushil.

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/