97 lines · c
1/**2 * css_get - obtain a reference on the specified css3 * @css: target css4 *5 * The caller must already have a reference.6 */7CGROUP_REF_FN_ATTRS8void css_get(struct cgroup_subsys_state *css)9{10 if (!(css->flags & CSS_NO_REF))11 percpu_ref_get(&css->refcnt);12}13CGROUP_REF_EXPORT(css_get)14 15/**16 * css_get_many - obtain references on the specified css17 * @css: target css18 * @n: number of references to get19 *20 * The caller must already have a reference.21 */22CGROUP_REF_FN_ATTRS23void css_get_many(struct cgroup_subsys_state *css, unsigned int n)24{25 if (!(css->flags & CSS_NO_REF))26 percpu_ref_get_many(&css->refcnt, n);27}28CGROUP_REF_EXPORT(css_get_many)29 30/**31 * css_tryget - try to obtain a reference on the specified css32 * @css: target css33 *34 * Obtain a reference on @css unless it already has reached zero and is35 * being released. This function doesn't care whether @css is on or36 * offline. The caller naturally needs to ensure that @css is accessible37 * but doesn't have to be holding a reference on it - IOW, RCU protected38 * access is good enough for this function. Returns %true if a reference39 * count was successfully obtained; %false otherwise.40 */41CGROUP_REF_FN_ATTRS42bool css_tryget(struct cgroup_subsys_state *css)43{44 if (!(css->flags & CSS_NO_REF))45 return percpu_ref_tryget(&css->refcnt);46 return true;47}48CGROUP_REF_EXPORT(css_tryget)49 50/**51 * css_tryget_online - try to obtain a reference on the specified css if online52 * @css: target css53 *54 * Obtain a reference on @css if it's online. The caller naturally needs55 * to ensure that @css is accessible but doesn't have to be holding a56 * reference on it - IOW, RCU protected access is good enough for this57 * function. Returns %true if a reference count was successfully obtained;58 * %false otherwise.59 */60CGROUP_REF_FN_ATTRS61bool css_tryget_online(struct cgroup_subsys_state *css)62{63 if (!(css->flags & CSS_NO_REF))64 return percpu_ref_tryget_live(&css->refcnt);65 return true;66}67CGROUP_REF_EXPORT(css_tryget_online)68 69/**70 * css_put - put a css reference71 * @css: target css72 *73 * Put a reference obtained via css_get() and css_tryget_online().74 */75CGROUP_REF_FN_ATTRS76void css_put(struct cgroup_subsys_state *css)77{78 if (!(css->flags & CSS_NO_REF))79 percpu_ref_put(&css->refcnt);80}81CGROUP_REF_EXPORT(css_put)82 83/**84 * css_put_many - put css references85 * @css: target css86 * @n: number of references to put87 *88 * Put references obtained via css_get() and css_tryget_online().89 */90CGROUP_REF_FN_ATTRS91void css_put_many(struct cgroup_subsys_state *css, unsigned int n)92{93 if (!(css->flags & CSS_NO_REF))94 percpu_ref_put_many(&css->refcnt, n);95}96CGROUP_REF_EXPORT(css_put_many)97