diff options
author | Tejun Heo <tj@kernel.org> | 2014-05-16 13:22:52 -0400 |
---|---|---|
committer | Tejun Heo <tj@kernel.org> | 2014-05-16 13:22:52 -0400 |
commit | 6f4524d355a86769b65d5420a6ef47fb0bba9b72 (patch) | |
tree | b0edfe7bfc0a20173041aa8811acf4629ccb020d /include/linux/cgroup.h | |
parent | 7a3bb24f7c5ceebad19b12b66fd832a27a7e90df (diff) |
cgroup: implement css_tryget()
Implement css_tryget() which tries to grab a cgroup_subsys_state's
reference as long as it already hasn't reached zero. Combined with
the recent css iterator changes to include offline && !released csses
during traversal, this can be used to access csses regardless of its
online state.
v2: Take the new flag CSS_NO_REF into account.
Signed-off-by: Tejun Heo <tj@kernel.org>
Acked-by: Li Zefan <lizefan@huawei.com>
Cc: Johannes Weiner <hannes@cmpxchg.org>
Diffstat (limited to 'include/linux/cgroup.h')
-rw-r--r-- | include/linux/cgroup.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/include/linux/cgroup.h b/include/linux/cgroup.h index b76999954beb..4afe544d3547 100644 --- a/include/linux/cgroup.h +++ b/include/linux/cgroup.h | |||
@@ -113,6 +113,24 @@ static inline void css_get(struct cgroup_subsys_state *css) | |||
113 | } | 113 | } |
114 | 114 | ||
115 | /** | 115 | /** |
116 | * css_tryget - try to obtain a reference on the specified css | ||
117 | * @css: target css | ||
118 | * | ||
119 | * Obtain a reference on @css unless it already has reached zero and is | ||
120 | * being released. This function doesn't care whether @css is on or | ||
121 | * offline. The caller naturally needs to ensure that @css is accessible | ||
122 | * but doesn't have to be holding a reference on it - IOW, RCU protected | ||
123 | * access is good enough for this function. Returns %true if a reference | ||
124 | * count was successfully obtained; %false otherwise. | ||
125 | */ | ||
126 | static inline bool css_tryget(struct cgroup_subsys_state *css) | ||
127 | { | ||
128 | if (!(css->flags & CSS_NO_REF)) | ||
129 | return percpu_ref_tryget(&css->refcnt); | ||
130 | return true; | ||
131 | } | ||
132 | |||
133 | /** | ||
116 | * css_tryget_online - try to obtain a reference on the specified css if online | 134 | * css_tryget_online - try to obtain a reference on the specified css if online |
117 | * @css: target css | 135 | * @css: target css |
118 | * | 136 | * |