aboutsummaryrefslogtreecommitdiffstats
path: root/include/litmus/wait.h
diff options
context:
space:
mode:
authorBjoern B. Brandenburg <bbb@cs.unc.edu>2011-07-21 14:37:36 -0400
committerBjoern B. Brandenburg <bbb@cs.unc.edu>2011-07-21 14:37:36 -0400
commitf5d05880c01fe2e25dbe06c69d55b5e3d4c1a82c (patch)
treef6efab5be26115b248ab0b360eeb73e9dd5586dc /include/litmus/wait.h
parenteab1497d8b46a2367a78d47a3bc35b9a1b68e2c2 (diff)
Add priority-ordered wait_queue_t implementation
Will be used by MPCP implementation.
Diffstat (limited to 'include/litmus/wait.h')
-rw-r--r--include/litmus/wait.h54
1 files changed, 54 insertions, 0 deletions
diff --git a/include/litmus/wait.h b/include/litmus/wait.h
new file mode 100644
index 000000000000..62884f5eb9c8
--- /dev/null
+++ b/include/litmus/wait.h
@@ -0,0 +1,54 @@
1#ifndef _LITMUS_WAIT_H_
2#define _LITMUS_WAIT_H_
3
4struct task_struct* __waitqueue_remove_first(wait_queue_head_t *wq);
5
6/* wrap regular wait_queue_t head */
7struct __prio_wait_queue {
8 wait_queue_t wq;
9
10 /* some priority point */
11 lt_t priority;
12};
13
14typedef struct __prio_wait_queue prio_wait_queue_t;
15
16static inline void init_prio_waitqueue_entry(prio_wait_queue_t *pwq,
17 struct task_struct* t,
18 lt_t priority)
19{
20 init_waitqueue_entry(&pwq->wq, t);
21 pwq->priority = priority;
22}
23
24static inline unsigned int __add_wait_queue_prio_exclusive(
25 wait_queue_head_t* head,
26 prio_wait_queue_t *new)
27{
28 struct list_head *pos;
29 unsigned int passed = 0;
30
31 new->wq.flags |= WQ_FLAG_EXCLUSIVE;
32
33 /* find a spot where the new entry is less than the next */
34 list_for_each(pos, &head->task_list) {
35 prio_wait_queue_t* queued = list_entry(pos, prio_wait_queue_t,
36 wq.task_list);
37
38 if (unlikely(lt_before(new->priority, queued->priority))) {
39 /* pos is not less than new, thus insert here */
40 __list_add(&new->wq.task_list, pos->prev, pos);
41 goto out;
42 }
43 passed++;
44 }
45
46 /* if we get to this point either the list is empty or every entry
47 * queued element is less than new.
48 * Let's add new to the end. */
49 list_add_tail(&new->wq.task_list, &head->task_list);
50out:
51 return passed;
52}
53
54#endif