1 #include <linux/sched.h>
2 #include <linux/swait.h>
4 void __init_swait_queue_head(struct swait_queue_head
*q
, const char *name
,
5 struct lock_class_key
*key
)
7 raw_spin_lock_init(&q
->lock
);
8 lockdep_set_class_and_name(&q
->lock
, key
, name
);
9 INIT_LIST_HEAD(&q
->task_list
);
11 EXPORT_SYMBOL(__init_swait_queue_head
);
14 * The thing about the wake_up_state() return value; I think we can ignore it.
16 * If for some reason it would return 0, that means the previously waiting
17 * task is already running, so it will observe condition true (or has already).
19 void swake_up_locked(struct swait_queue_head
*q
)
21 struct swait_queue
*curr
;
23 if (list_empty(&q
->task_list
))
26 curr
= list_first_entry(&q
->task_list
, typeof(*curr
), task_list
);
27 wake_up_process(curr
->task
);
28 list_del_init(&curr
->task_list
);
30 EXPORT_SYMBOL(swake_up_locked
);
32 void swake_up(struct swait_queue_head
*q
)
39 raw_spin_lock_irqsave(&q
->lock
, flags
);
41 raw_spin_unlock_irqrestore(&q
->lock
, flags
);
43 EXPORT_SYMBOL(swake_up
);
46 * Does not allow usage from IRQ disabled, since we must be able to
47 * release IRQs to guarantee bounded hold time.
49 void swake_up_all(struct swait_queue_head
*q
)
51 struct swait_queue
*curr
;
57 raw_spin_lock_irq(&q
->lock
);
58 list_splice_init(&q
->task_list
, &tmp
);
59 while (!list_empty(&tmp
)) {
60 curr
= list_first_entry(&tmp
, typeof(*curr
), task_list
);
62 wake_up_state(curr
->task
, TASK_NORMAL
);
63 list_del_init(&curr
->task_list
);
68 raw_spin_unlock_irq(&q
->lock
);
69 raw_spin_lock_irq(&q
->lock
);
71 raw_spin_unlock_irq(&q
->lock
);
73 EXPORT_SYMBOL(swake_up_all
);
75 void __prepare_to_swait(struct swait_queue_head
*q
, struct swait_queue
*wait
)
78 if (list_empty(&wait
->task_list
))
79 list_add(&wait
->task_list
, &q
->task_list
);
82 void prepare_to_swait(struct swait_queue_head
*q
, struct swait_queue
*wait
, int state
)
86 raw_spin_lock_irqsave(&q
->lock
, flags
);
87 __prepare_to_swait(q
, wait
);
88 set_current_state(state
);
89 raw_spin_unlock_irqrestore(&q
->lock
, flags
);
91 EXPORT_SYMBOL(prepare_to_swait
);
93 long prepare_to_swait_event(struct swait_queue_head
*q
, struct swait_queue
*wait
, int state
)
95 if (signal_pending_state(state
, current
))
98 prepare_to_swait(q
, wait
, state
);
102 EXPORT_SYMBOL(prepare_to_swait_event
);
104 void __finish_swait(struct swait_queue_head
*q
, struct swait_queue
*wait
)
106 __set_current_state(TASK_RUNNING
);
107 if (!list_empty(&wait
->task_list
))
108 list_del_init(&wait
->task_list
);
111 void finish_swait(struct swait_queue_head
*q
, struct swait_queue
*wait
)
115 __set_current_state(TASK_RUNNING
);
117 if (!list_empty_careful(&wait
->task_list
)) {
118 raw_spin_lock_irqsave(&q
->lock
, flags
);
119 list_del_init(&wait
->task_list
);
120 raw_spin_unlock_irqrestore(&q
->lock
, flags
);
123 EXPORT_SYMBOL(finish_swait
);
This page took 0.039566 seconds and 5 git commands to generate.