X-Git-Url: https://git.whamcloud.com/?p=fs%2Flustre-release.git;a=blobdiff_plain;f=lnet%2Finclude%2Flibcfs%2Flinux%2Flinux-prim.h;h=9ae57cde1f9b958aa23ee6cab8691ea730b0f1db;hp=a8153dd2900e2dfb90c97b27a54c34635b967eb9;hb=991ab17e59a12954cb839627b0c542486cc3603e;hpb=39eabbad40b25b1950ae21c9ba72e8de4098565b diff --git a/lnet/include/libcfs/linux/linux-prim.h b/lnet/include/libcfs/linux/linux-prim.h index a8153dd..9ae57cd 100644 --- a/lnet/include/libcfs/linux/linux-prim.h +++ b/lnet/include/libcfs/linux/linux-prim.h @@ -201,6 +201,94 @@ static inline void cfs_pause(cfs_duration_t ticks) schedule_timeout(ticks); } +#ifndef wait_event_timeout /* Only for RHEL3 2.4.21 kernel */ +#define __wait_event_timeout(wq, condition, timeout, ret) \ +do { \ + int __ret = 0; \ + if (!(condition)) { \ + wait_queue_t __wait; \ + unsigned long expire; \ + \ + init_waitqueue_entry(&__wait, current); \ + expire = timeout + jiffies; \ + add_wait_queue(&wq, &__wait); \ + for (;;) { \ + set_current_state(TASK_UNINTERRUPTIBLE); \ + if (condition) \ + break; \ + if (jiffies > expire) { \ + ret = jiffies - expire; \ + break; \ + } \ + schedule_timeout(timeout); \ + } \ + current->state = TASK_RUNNING; \ + remove_wait_queue(&wq, &__wait); \ + } \ +} while (0) +/* + retval == 0; condition met; we're good. + retval > 0; timed out. +*/ +#define cfs_waitq_wait_event_timeout(wq, condition, timeout) \ +({ \ + int __ret = 0; \ + if (!(condition)) \ + __wait_event_timeout(wq, condition, timeout, __ret); \ + __ret; \ +}) +#else +#define cfs_waitq_wait_event_timeout wait_event_timeout +#endif + +#ifndef wait_event_interruptible_timeout /* Only for RHEL3 2.4.21 kernel */ +#define __wait_event_interruptible_timeout(wq, condition, timeout, ret) \ +do { \ + int __ret = 0; \ + if (!(condition)) { \ + wait_queue_t __wait; \ + unsigned long expire; \ + \ + init_waitqueue_entry(&__wait, current); \ + expire = timeout + jiffies; \ + add_wait_queue(&wq, &__wait); \ + for (;;) { \ + set_current_state(TASK_INTERRUPTIBLE); \ + if (condition) \ + break; \ + if (jiffies > expire) { \ + ret = jiffies - expire; \ + break; \ + } \ + if (!signal_pending(current)) { \ + schedule_timeout(timeout); \ + continue; \ + } \ + ret = -ERESTARTSYS; \ + break; \ + } \ + current->state = TASK_RUNNING; \ + remove_wait_queue(&wq, &__wait); \ + } \ +} while (0) + +/* + retval == 0; condition met; we're good. + retval < 0; interrupted by signal. + retval > 0; timed out. +*/ +#define cfs_waitq_wait_event_interruptible_timeout(wq, condition, timeout) \ +({ \ + int __ret = 0; \ + if (!(condition)) \ + __wait_event_interruptible_timeout(wq, condition, \ + timeout, __ret); \ + __ret; \ +}) +#else +#define cfs_waitq_wait_event_interruptible_timeout wait_event_interruptible_timeout +#endif + #else /* !__KERNEL__ */ typedef struct proc_dir_entry cfs_proc_dir_entry_t;