Commit | Line | Data |
---|---|---|
b5234c06 MD |
1 | #ifndef _UST_WAIT_H |
2 | #define _UST_WAIT_H | |
3 | ||
4 | /* | |
5 | * Copyright (C) 2011 Mathieu Desnoyers <mathieu.desnoyers@efficios.com> | |
6 | * | |
7 | * This library is free software; you can redistribute it and/or | |
8 | * modify it under the terms of the GNU Lesser General Public | |
9 | * License as published by the Free Software Foundation; version 2.1 of | |
10 | * the License. | |
11 | * | |
12 | * This library is distributed in the hope that it will be useful, | |
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 | * Lesser General Public License for more details. | |
16 | * | |
17 | * You should have received a copy of the GNU Lesser General Public | |
18 | * License along with this library; if not, write to the Free Software | |
19 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
20 | */ | |
21 | ||
22 | #include <poll.h> | |
23 | ||
24 | /* | |
25 | * Wait until "cond" gets true or timeout (in ms). | |
26 | */ | |
27 | #define wait_cond_interruptible_timeout(_cond, _timeout) \ | |
28 | ({ \ | |
29 | int __ret = 0, __pollret; \ | |
30 | int __timeout = _timeout; \ | |
31 | \ | |
32 | for (;;) { \ | |
b472cfc0 | 33 | if (_cond) \ |
b5234c06 MD |
34 | break; \ |
35 | if (__timeout <= 0) { \ | |
36 | __ret = -ETIMEDOUT; \ | |
37 | break; \ | |
38 | } \ | |
39 | __pollret = poll(NULL, 0, 10); /* wait 10ms */ \ | |
40 | if (__pollret < 0) { \ | |
9dcb02ef | 41 | __ret = -errno; \ |
b5234c06 MD |
42 | break; \ |
43 | } \ | |
44 | __timeout -= 10; \ | |
45 | } \ | |
46 | __ret; \ | |
47 | }) | |
48 | ||
49 | ||
50 | #endif /* _UST_WAIT_H */ |