summaryrefslogtreecommitdiffstats
path: root/drivers/gpu/nvgpu/include
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/gpu/nvgpu/include')
-rw-r--r--drivers/gpu/nvgpu/include/nvgpu/linux/cond.h51
1 files changed, 49 insertions, 2 deletions
diff --git a/drivers/gpu/nvgpu/include/nvgpu/linux/cond.h b/drivers/gpu/nvgpu/include/nvgpu/linux/cond.h
index 3eb52861..01ca5291 100644
--- a/drivers/gpu/nvgpu/include/nvgpu/linux/cond.h
+++ b/drivers/gpu/nvgpu/include/nvgpu/linux/cond.h
@@ -24,10 +24,57 @@ struct nvgpu_cond {
24 wait_queue_head_t wq; 24 wait_queue_head_t wq;
25}; 25};
26 26
27/**
28 * NVGPU_COND_WAIT - Wait for a condition to be true
29 *
30 * @c - The condition variable to sleep on
31 * @condition - The condition that needs to be true
32 * @timeout_ms - Timeout in milliseconds, or 0 for infinite wait
33 *
34 * Wait for a condition to become true. Returns -ETIMEOUT if
35 * the wait timed out with condition false.
36 */
27#define NVGPU_COND_WAIT(c, condition, timeout_ms) \ 37#define NVGPU_COND_WAIT(c, condition, timeout_ms) \
28 wait_event_timeout((c)->wq, condition, timeout_ms) 38({\
39 int ret = 0; \
40 long _timeout_ms = timeout_ms;\
41 if (_timeout_ms > 0) { \
42 long _ret = wait_event_timeout((c)->wq, condition, \
43 msecs_to_jiffies(_timeout_ms)); \
44 if (_ret == 0) \
45 ret = -ETIMEDOUT; \
46 } else { \
47 wait_event((c)->wq, condition); \
48 } \
49 ret;\
50})
29 51
52/**
53 * NVGPU_COND_WAIT_INTERRUPTIBLE - Wait for a condition to be true
54 *
55 * @c - The condition variable to sleep on
56 * @condition - The condition that needs to be true
57 * @timeout_ms - Timeout in milliseconds, or 0 for infinite wait
58 *
59 * Wait for a condition to become true. Returns -ETIMEOUT if
60 * the wait timed out with condition false or -ERESTARTSYS on
61 * signal.
62 */
30#define NVGPU_COND_WAIT_INTERRUPTIBLE(c, condition, timeout_ms) \ 63#define NVGPU_COND_WAIT_INTERRUPTIBLE(c, condition, timeout_ms) \
31 wait_event_interruptible_timeout((c)->wq, condition, timeout_ms) 64({ \
65 int ret = 0; \
66 long _timeout_ms = timeout_ms;\
67 if (_timeout_ms > 0) { \
68 long _ret = wait_event_interruptible_timeout((c)->wq, condition, \
69 msecs_to_jiffies(_timeout_ms)); \
70 if (_ret == 0) \
71 ret = -ETIMEDOUT; \
72 else if (_ret == -ERESTARTSYS) \
73 ret = -ERESTARTSYS; \
74 } else { \
75 wait_event_interruptible((c)->wq, condition); \
76 } \
77 ret; \
78})
32 79
33#endif /* __NVGPU_LOCK_LINUX_H__ */ 80#endif /* __NVGPU_LOCK_LINUX_H__ */