Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / kernel / user-return-notifier.c
blobeb27fd3430a291df4c714b1b462b69d5f9490366
2 #include <linux/user-return-notifier.h>
3 #include <linux/percpu.h>
4 #include <linux/sched.h>
5 #include <linux/module.h>
7 static DEFINE_PER_CPU(struct hlist_head, return_notifier_list);
9 /*
10 * Request a notification when the current cpu returns to userspace. Must be
11 * called in atomic context. The notifier will also be called in atomic
12 * context.
14 void user_return_notifier_register(struct user_return_notifier *urn)
16 set_tsk_thread_flag(current, TIF_USER_RETURN_NOTIFY);
17 hlist_add_head(&urn->link, &__get_cpu_var(return_notifier_list));
19 EXPORT_SYMBOL_GPL(user_return_notifier_register);
22 * Removes a registered user return notifier. Must be called from atomic
23 * context, and from the same cpu registration occured in.
25 void user_return_notifier_unregister(struct user_return_notifier *urn)
27 hlist_del(&urn->link);
28 if (hlist_empty(&__get_cpu_var(return_notifier_list)))
29 clear_tsk_thread_flag(current, TIF_USER_RETURN_NOTIFY);
31 EXPORT_SYMBOL_GPL(user_return_notifier_unregister);
33 /* Calls registered user return notifiers */
34 void fire_user_return_notifiers(void)
36 struct user_return_notifier *urn;
37 struct hlist_node *tmp1, *tmp2;
38 struct hlist_head *head;
40 head = &get_cpu_var(return_notifier_list);
41 hlist_for_each_entry_safe(urn, tmp1, tmp2, head, link)
42 urn->on_user_return(urn);
43 put_cpu_var(return_notifier_list);