1 #include <linux/slab.h>
2 #include <linux/spinlock.h>
3 #include <linux/once.h>
4 #include <linux/random.h>
7 struct work_struct work
;
8 struct static_key
*key
;
11 static void once_deferred(struct work_struct
*w
)
13 struct once_work
*work
;
15 work
= container_of(w
, struct once_work
, work
);
16 BUG_ON(!static_key_enabled(work
->key
));
17 static_key_slow_dec(work
->key
);
21 static void once_disable_jump(struct static_key
*key
)
25 w
= kmalloc(sizeof(*w
), GFP_ATOMIC
);
29 INIT_WORK(&w
->work
, once_deferred
);
31 schedule_work(&w
->work
);
34 static DEFINE_SPINLOCK(once_lock
);
36 bool __do_once_start(bool *done
, unsigned long *flags
)
39 spin_lock_irqsave(&once_lock
, *flags
);
41 spin_unlock_irqrestore(&once_lock
, *flags
);
42 /* Keep sparse happy by restoring an even lock count on
43 * this lock. In case we return here, we don't call into
44 * __do_once_done but return early in the DO_ONCE() macro.
52 EXPORT_SYMBOL(__do_once_start
);
54 void __do_once_done(bool *done
, struct static_key
*once_key
,
59 spin_unlock_irqrestore(&once_lock
, *flags
);
60 once_disable_jump(once_key
);
62 EXPORT_SYMBOL(__do_once_done
);