]> rtime.felk.cvut.cz Git - zynq/linux.git/blob - kernel/sched/swait.c
Apply preempt_rt patch-4.9-rt1.patch.xz
[zynq/linux.git] / kernel / sched / swait.c
1 #include <linux/sched.h>
2 #include <linux/swait.h>
3 #include <linux/suspend.h>
4
5 void __init_swait_queue_head(struct swait_queue_head *q, const char *name,
6                              struct lock_class_key *key)
7 {
8         raw_spin_lock_init(&q->lock);
9         lockdep_set_class_and_name(&q->lock, key, name);
10         INIT_LIST_HEAD(&q->task_list);
11 }
12 EXPORT_SYMBOL(__init_swait_queue_head);
13
14 /*
15  * The thing about the wake_up_state() return value; I think we can ignore it.
16  *
17  * If for some reason it would return 0, that means the previously waiting
18  * task is already running, so it will observe condition true (or has already).
19  */
20 void swake_up_locked(struct swait_queue_head *q)
21 {
22         struct swait_queue *curr;
23
24         if (list_empty(&q->task_list))
25                 return;
26
27         curr = list_first_entry(&q->task_list, typeof(*curr), task_list);
28         wake_up_process(curr->task);
29         list_del_init(&curr->task_list);
30 }
31 EXPORT_SYMBOL(swake_up_locked);
32
33 void swake_up_all_locked(struct swait_queue_head *q)
34 {
35         struct swait_queue *curr;
36         int wakes = 0;
37
38         while (!list_empty(&q->task_list)) {
39
40                 curr = list_first_entry(&q->task_list, typeof(*curr),
41                                         task_list);
42                 wake_up_process(curr->task);
43                 list_del_init(&curr->task_list);
44                 wakes++;
45         }
46         if (pm_in_action)
47                 return;
48         WARN(wakes > 2, "complete_all() with %d waiters\n", wakes);
49 }
50 EXPORT_SYMBOL(swake_up_all_locked);
51
52 void swake_up(struct swait_queue_head *q)
53 {
54         unsigned long flags;
55
56         if (!swait_active(q))
57                 return;
58
59         raw_spin_lock_irqsave(&q->lock, flags);
60         swake_up_locked(q);
61         raw_spin_unlock_irqrestore(&q->lock, flags);
62 }
63 EXPORT_SYMBOL(swake_up);
64
65 /*
66  * Does not allow usage from IRQ disabled, since we must be able to
67  * release IRQs to guarantee bounded hold time.
68  */
69 void swake_up_all(struct swait_queue_head *q)
70 {
71         struct swait_queue *curr;
72         LIST_HEAD(tmp);
73
74         if (!swait_active(q))
75                 return;
76
77         WARN_ON(irqs_disabled());
78         raw_spin_lock_irq(&q->lock);
79         list_splice_init(&q->task_list, &tmp);
80         while (!list_empty(&tmp)) {
81                 curr = list_first_entry(&tmp, typeof(*curr), task_list);
82
83                 wake_up_state(curr->task, TASK_NORMAL);
84                 list_del_init(&curr->task_list);
85
86                 if (list_empty(&tmp))
87                         break;
88
89                 raw_spin_unlock_irq(&q->lock);
90                 raw_spin_lock_irq(&q->lock);
91         }
92         raw_spin_unlock_irq(&q->lock);
93 }
94 EXPORT_SYMBOL(swake_up_all);
95
96 void __prepare_to_swait(struct swait_queue_head *q, struct swait_queue *wait)
97 {
98         wait->task = current;
99         if (list_empty(&wait->task_list))
100                 list_add(&wait->task_list, &q->task_list);
101 }
102
103 void prepare_to_swait(struct swait_queue_head *q, struct swait_queue *wait, int state)
104 {
105         unsigned long flags;
106
107         raw_spin_lock_irqsave(&q->lock, flags);
108         __prepare_to_swait(q, wait);
109         set_current_state(state);
110         raw_spin_unlock_irqrestore(&q->lock, flags);
111 }
112 EXPORT_SYMBOL(prepare_to_swait);
113
114 long prepare_to_swait_event(struct swait_queue_head *q, struct swait_queue *wait, int state)
115 {
116         if (signal_pending_state(state, current))
117                 return -ERESTARTSYS;
118
119         prepare_to_swait(q, wait, state);
120
121         return 0;
122 }
123 EXPORT_SYMBOL(prepare_to_swait_event);
124
125 void __finish_swait(struct swait_queue_head *q, struct swait_queue *wait)
126 {
127         __set_current_state(TASK_RUNNING);
128         if (!list_empty(&wait->task_list))
129                 list_del_init(&wait->task_list);
130 }
131
132 void finish_swait(struct swait_queue_head *q, struct swait_queue *wait)
133 {
134         unsigned long flags;
135
136         __set_current_state(TASK_RUNNING);
137
138         if (!list_empty_careful(&wait->task_list)) {
139                 raw_spin_lock_irqsave(&q->lock, flags);
140                 list_del_init(&wait->task_list);
141                 raw_spin_unlock_irqrestore(&q->lock, flags);
142         }
143 }
144 EXPORT_SYMBOL(finish_swait);