Motr  M0
refs.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2020 Seagate Technology LLC and/or its Affiliates
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  * For any questions about this software or licensing,
17  * please email opensource@seagate.com or cortx-questions@seagate.com.
18  *
19  */
20 
21 
22 #include "lib/refs.h"
23 
24 void m0_ref_init(struct m0_ref *ref, int init_num,
25  void (*release) (struct m0_ref *ref))
26 {
27  m0_atomic64_set(&ref->ref_cnt, init_num);
28  ref->release = release;
29  m0_mb();
30 }
31 
32 M0_INTERNAL void m0_ref_get(struct m0_ref *ref)
33 {
34  m0_atomic64_inc(&ref->ref_cnt);
35  m0_mb();
36 }
37 
38 M0_INTERNAL void m0_ref_put(struct m0_ref *ref)
39 {
41  ref->release(ref);
42 }
43 
44 M0_INTERNAL int64_t m0_ref_read(const struct m0_ref *ref)
45 {
46  return m0_atomic64_get(&ref->ref_cnt);
47 }
void(* release)(struct m0_ref *ref)
Definition: refs.h:43
static void m0_atomic64_inc(struct m0_atomic64 *a)
string release
Definition: conf.py:42
M0_INTERNAL void m0_ref_put(struct m0_ref *ref)
Definition: refs.c:38
void m0_ref_init(struct m0_ref *ref, int init_num, void(*release)(struct m0_ref *ref))
Definition: refs.c:24
M0_INTERNAL void m0_ref_get(struct m0_ref *ref)
Definition: refs.c:32
Definition: refs.h:34
struct m0_atomic64 ref_cnt
Definition: refs.h:38
static bool m0_atomic64_dec_and_test(struct m0_atomic64 *a)
static int64_t m0_atomic64_get(const struct m0_atomic64 *a)
static void m0_mb(void)
M0_INTERNAL int64_t m0_ref_read(const struct m0_ref *ref)
Definition: refs.c:44
static void m0_atomic64_set(struct m0_atomic64 *a, int64_t num)