]> git.karo-electronics.de Git - mv-sheeva.git/blob - include/linux/slow-work.h
SLOW_WORK: Add delayed_slow_work support
[mv-sheeva.git] / include / linux / slow-work.h
1 /* Worker thread pool for slow items, such as filesystem lookups or mkdirs
2  *
3  * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
4  * Written by David Howells (dhowells@redhat.com)
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public Licence
8  * as published by the Free Software Foundation; either version
9  * 2 of the Licence, or (at your option) any later version.
10  *
11  * See Documentation/slow-work.txt
12  */
13
14 #ifndef _LINUX_SLOW_WORK_H
15 #define _LINUX_SLOW_WORK_H
16
17 #ifdef CONFIG_SLOW_WORK
18
19 #include <linux/sysctl.h>
20 #include <linux/timer.h>
21
22 struct slow_work;
23
24 /*
25  * The operations used to support slow work items
26  */
27 struct slow_work_ops {
28         /* owner */
29         struct module *owner;
30
31         /* get a ref on a work item
32          * - return 0 if successful, -ve if not
33          */
34         int (*get_ref)(struct slow_work *work);
35
36         /* discard a ref to a work item */
37         void (*put_ref)(struct slow_work *work);
38
39         /* execute a work item */
40         void (*execute)(struct slow_work *work);
41 };
42
43 /*
44  * A slow work item
45  * - A reference is held on the parent object by the thread pool when it is
46  *   queued
47  */
48 struct slow_work {
49         struct module           *owner; /* the owning module */
50         unsigned long           flags;
51 #define SLOW_WORK_PENDING       0       /* item pending (further) execution */
52 #define SLOW_WORK_EXECUTING     1       /* item currently executing */
53 #define SLOW_WORK_ENQ_DEFERRED  2       /* item enqueue deferred */
54 #define SLOW_WORK_VERY_SLOW     3       /* item is very slow */
55 #define SLOW_WORK_CANCELLING    4       /* item is being cancelled, don't enqueue */
56 #define SLOW_WORK_DELAYED       5       /* item is struct delayed_slow_work with active timer */
57         const struct slow_work_ops *ops; /* operations table for this item */
58         struct list_head        link;   /* link in queue */
59 };
60
61 struct delayed_slow_work {
62         struct slow_work        work;
63         struct timer_list       timer;
64 };
65
66 /**
67  * slow_work_init - Initialise a slow work item
68  * @work: The work item to initialise
69  * @ops: The operations to use to handle the slow work item
70  *
71  * Initialise a slow work item.
72  */
73 static inline void slow_work_init(struct slow_work *work,
74                                   const struct slow_work_ops *ops)
75 {
76         work->flags = 0;
77         work->ops = ops;
78         INIT_LIST_HEAD(&work->link);
79 }
80
81 /**
82  * slow_work_init - Initialise a delayed slow work item
83  * @work: The work item to initialise
84  * @ops: The operations to use to handle the slow work item
85  *
86  * Initialise a delayed slow work item.
87  */
88 static inline void delayed_slow_work_init(struct delayed_slow_work *dwork,
89                                           const struct slow_work_ops *ops)
90 {
91         init_timer(&dwork->timer);
92         slow_work_init(&dwork->work, ops);
93 }
94
95 /**
96  * vslow_work_init - Initialise a very slow work item
97  * @work: The work item to initialise
98  * @ops: The operations to use to handle the slow work item
99  *
100  * Initialise a very slow work item.  This item will be restricted such that
101  * only a certain number of the pool threads will be able to execute items of
102  * this type.
103  */
104 static inline void vslow_work_init(struct slow_work *work,
105                                    const struct slow_work_ops *ops)
106 {
107         work->flags = 1 << SLOW_WORK_VERY_SLOW;
108         work->ops = ops;
109         INIT_LIST_HEAD(&work->link);
110 }
111
112 extern int slow_work_enqueue(struct slow_work *work);
113 extern void slow_work_cancel(struct slow_work *work);
114 extern int slow_work_register_user(struct module *owner);
115 extern void slow_work_unregister_user(struct module *owner);
116
117 extern int delayed_slow_work_enqueue(struct delayed_slow_work *dwork,
118                                      unsigned long delay);
119
120 static inline void delayed_slow_work_cancel(struct delayed_slow_work *dwork)
121 {
122         slow_work_cancel(&dwork->work);
123 }
124
125 #ifdef CONFIG_SYSCTL
126 extern ctl_table slow_work_sysctls[];
127 #endif
128
129 #endif /* CONFIG_SLOW_WORK */
130 #endif /* _LINUX_SLOW_WORK_H */