2 * Distributed under the terms of the GNU GPL version 2.
5 #include <linux/module.h>
6 #include <linux/rcupdate.h>
7 #include <linux/sched.h>
8 #include <linux/tqueue.h>
10 #include <linux/completion.h>
15 #error "SMP configurations not supported for RCU backport."
18 static int default_blimit = 10;
20 static int qhimark = 10000;
21 static int qlowmark = 100;
23 static struct rcu_head *head, **tail;
26 static struct tq_struct rcu_task;
29 * Invoke the completed RCU callbacks. They are expected to be in
32 static void rcu_task_routine(void *unused)
34 struct rcu_head *list, *next;
48 if (++count >= blimit)
55 if (blimit == INT_MAX && qlen <= qlowmark)
56 blimit = default_blimit;
59 schedule_task(&rcu_task);
63 static inline void force_quiescent_state(void)
65 current->need_resched = 1;
69 * call_rcu - Queue an RCU callback for invocation after a grace period.
70 * @rcu: structure to be used for queueing the RCU updates.
71 * @func: actual update function to be invoked after the grace period
73 * The update function will be invoked some time after a full grace
74 * period elapses, in other words after all currently executing RCU
75 * read-side critical sections have completed. RCU read-side critical
76 * sections are delimited by rcu_read_lock() and rcu_read_unlock(),
79 void call_rcu(struct rcu_head *rcu, void (*func)(struct rcu_head *rcu))
83 /* FIXME? Following may be mildly expensive, may be worthwhile to
84 optimize common case. */
85 schedule_task(&rcu_task);
89 local_irq_save(flags);
92 if (unlikely(++qlen > qhimark)) {
94 force_quiescent_state();
96 local_irq_restore(flags);
98 EXPORT_SYMBOL(call_rcu);
104 blimit = default_blimit;
105 rcu_task.routine = rcu_task_routine;
108 struct rcu_synchronize {
109 struct rcu_head head;
110 struct completion completion;
113 /* Because of FASTCALL declaration of complete, we use this wrapper */
114 static void wakeme_after_rcu(struct rcu_head *head)
116 struct rcu_synchronize *rcu;
118 rcu = container_of(head, struct rcu_synchronize, head);
119 complete(&rcu->completion);
123 * synchronize_rcu - wait until a grace period has elapsed.
125 * Control will return to the caller some time after a full grace
126 * period has elapsed, in other words after all currently executing RCU
127 * read-side critical sections have completed. RCU read-side critical
128 * sections are delimited by rcu_read_lock() and rcu_read_unlock(),
131 * If your read-side code is not protected by rcu_read_lock(), do -not-
132 * use synchronize_rcu().
134 void synchronize_rcu(void)
136 struct rcu_synchronize rcu;
138 init_completion(&rcu.completion);
139 /* Will wake me after RCU finished */
140 call_rcu(&rcu.head, wakeme_after_rcu);
143 wait_for_completion(&rcu.completion);
145 EXPORT_SYMBOL(synchronize_rcu);