[OpenAFS-devel] afs_osi_Sleep and afs_osi_Wakeup on Linux

chas williams chas@cmf.nrl.navy.mil
Mon, 03 Jun 2002 18:52:21 -0400


In message <OF7F777427.0C0E6194-ON85256BCD.0071CA60@in.ibm.com>,"Srikanth Vishw
>while (seq == evp->seq) {
>        AFS_ASSERT_GLOCK();
>        AFS_GUNLOCK();
>        interruptible_sleep_on(&evp->cond);
>        AFS_GLOCK();
>...
>Is there a better way to do this ? May be a Linux API ? Something
>like Solaris's cv_wait(kcondvar_t *, kmutex_t *) would be nice.

this is a somewhat fairly well known problem with using interruptible_sleep_on
see pg 286 of linux device drivers second edition.   you need to put the 
event on the wait queue before you do anything that trigger the corresponding
wake_up.  i think this would be more correct than the unlock_/lock_kernel idea. 
something like (and this probably isnt quite right, but close i hope):

wait_queue_t wait;
init_waitqueue_entry(&wait, current);

/* blah blah blah */

add_wait_queue(&evp->cond, &wait);
set_current_state(TASK_INTERRUPTIBLE);
while (seq == evp->seq) {
        AFS_ASSERT_GLOCK();
        AFS_GUNLOCK();
	schedule();
        AFS_GLOCK();

	/* blah blah blah */
}
set_current_state(TASK_RUNNING);
remove_wait_queue(&evp->cond, &wait);