VirtualBox

source: vbox/trunk/src/VBox/Additions/linux/module/waitcompat.h@ 16684

Last change on this file since 16684 was 6278, checked in by vboxsync, 17 years ago

Guest Additions (Linux): fixed VBOXGUEST_IOCTL_WAITEVENT ioctl in kernel module

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 4.4 KB
Line 
1/* copied from linux/wait.h */
2
3#ifndef wait_event_timeout
4#define wait_event_timeout(wq, condition, timeout) \
5({ \
6 long __ret = timeout; \
7 if (!(condition)) \
8 __wait_event_timeout(wq, condition, __ret); \
9 __ret; \
10 })
11
12#define __wait_event_timeout(wq, condition, ret) \
13do { \
14 wait_queue_t __wait; \
15 init_waitqueue_entry(&__wait, current); \
16 \
17 add_wait_queue(&wq, &__wait); \
18 for (;;) { \
19 set_current_state(TASK_UNINTERRUPTIBLE); \
20 if (condition) \
21 break; \
22 ret = schedule_timeout(ret); \
23 if (!ret) \
24 break; \
25 } \
26 current->state = TASK_RUNNING; \
27 remove_wait_queue(&wq, &__wait); \
28} while (0)
29#endif
30
31#ifndef wait_event_interruptible_timeout
32
33/* We need to define these ones here as they only exist in kernels 2.6 and up */
34
35#define __wait_event_interruptible_timeout(wq, condition, timeout, ret) \
36do { \
37 int __ret = 0; \
38 if (!(condition)) { \
39 wait_queue_t __wait; \
40 unsigned long expire; \
41 init_waitqueue_entry(&__wait, current); \
42 \
43 expire = timeout + jiffies; \
44 add_wait_queue(&wq, &__wait); \
45 for (;;) { \
46 set_current_state(TASK_INTERRUPTIBLE); \
47 if (condition) \
48 break; \
49 if (jiffies > expire) { \
50 ret = jiffies - expire; \
51 break; \
52 } \
53 if (!signal_pending(current)) { \
54 schedule_timeout(timeout); \
55 continue; \
56 } \
57 ret = -ERESTARTSYS; \
58 break; \
59 } \
60 current->state = TASK_RUNNING; \
61 remove_wait_queue(&wq, &__wait); \
62 } \
63} while (0)
64
65/*
66 retval == 0; condition met; we're good.
67 retval < 0; interrupted by signal.
68 retval > 0; timed out.
69*/
70#define wait_event_interruptible_timeout(wq, condition, timeout) \
71({ \
72 int __ret = 0; \
73 if (!(condition)) \
74 __wait_event_interruptible_timeout(wq, condition, \
75 timeout, __ret); \
76 __ret; \
77})
78
79#endif /* wait_event_interruptible_timeout not defined */
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette