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/