Motr  M0
atomic64.h
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2012-2020 Seagate Technology LLC and/or its Affiliates
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * For any questions about this software or licensing,
18  * please email opensource@seagate.com or cortx-questions@seagate.com.
19  *
20  */
21 
22 #pragma once
23 #ifndef __MOTR_LIB_LINUX_KERNEL_ATOMIC64_H__
24 #define __MOTR_LIB_LINUX_KERNEL_ATOMIC64_H__
25 
26 #include <asm/atomic.h> /* atomic64_set */
27 #include "lib/misc.h" /* mb */
28 
37 struct m0_atomic64 {
38  atomic64_t a_value;
39 };
40 
41 static inline void m0_atomic64_set(struct m0_atomic64 *a, int64_t num)
42 {
43  M0_CASSERT(sizeof a->a_value == sizeof num);
44  atomic64_set(&a->a_value, num);
45 }
46 
47 static inline int64_t m0_atomic64_get(const struct m0_atomic64 *a)
48 {
49  return atomic64_read(&a->a_value);
50 }
51 
52 static inline void m0_atomic64_inc(struct m0_atomic64 *a)
53 {
54  atomic64_inc(&a->a_value);
55 }
56 
57 static inline void m0_atomic64_dec(struct m0_atomic64 *a)
58 {
59  atomic64_dec(&a->a_value);
60 }
61 
62 static inline void m0_atomic64_add(struct m0_atomic64 *a, int64_t num)
63 {
64  atomic64_add(num, &a->a_value);
65 }
66 
67 static inline void m0_atomic64_sub(struct m0_atomic64 *a, int64_t num)
68 {
69  atomic64_sub(num, &a->a_value);
70 }
71 
72 static inline int64_t
73 m0_atomic64_add_return(struct m0_atomic64 *a, int64_t delta)
74 {
75  return atomic64_add_return(delta, &a->a_value);
76 }
77 
78 static inline int64_t
79 m0_atomic64_sub_return(struct m0_atomic64 *a, int64_t delta)
80 {
81  return atomic64_sub_return(delta, &a->a_value);
82 }
83 
84 static inline bool m0_atomic64_inc_and_test(struct m0_atomic64 *a)
85 {
86  return atomic64_inc_and_test(&a->a_value);
87 }
88 
89 static inline bool m0_atomic64_dec_and_test(struct m0_atomic64 *a)
90 {
91  return atomic64_dec_and_test(&a->a_value);
92 }
93 
94 static inline bool m0_atomic64_cas(int64_t * loc, int64_t old, int64_t new)
95 {
96  return cmpxchg64(loc, old, new) == old;
97 }
98 
99 static inline void m0_mb(void)
100 {
101  mb();
102 }
103 
105 #endif /* __MOTR_LIB_LINUX_KERNEL_ATOMIC64_H__ */
106 
107 /*
108  * Local variables:
109  * c-indentation-style: "K&R"
110  * c-basic-offset: 8
111  * tab-width: 8
112  * fill-column: 80
113  * scroll-step: 1
114  * End:
115  */
static void m0_atomic64_sub(struct m0_atomic64 *a, int64_t num)
Definition: atomic64.h:67
static bool m0_atomic64_dec_and_test(struct m0_atomic64 *a)
Definition: atomic64.h:89
static void m0_atomic64_add(struct m0_atomic64 *a, int64_t num)
Definition: atomic64.h:62
#define M0_CASSERT(cond)
static void m0_atomic64_inc(struct m0_atomic64 *a)
Definition: atomic64.h:52
static int64_t m0_atomic64_sub_return(struct m0_atomic64 *a, int64_t delta)
Definition: atomic64.h:79
static int64_t m0_atomic64_get(const struct m0_atomic64 *a)
Definition: atomic64.h:47
static bool m0_atomic64_cas(int64_t *loc, int64_t old, int64_t new)
Definition: atomic64.h:94
struct mock_balloc mb
Definition: ad.c:173
static int64_t m0_atomic64_add_return(struct m0_atomic64 *a, int64_t delta)
Definition: atomic64.h:73
static bool m0_atomic64_inc_and_test(struct m0_atomic64 *a)
Definition: atomic64.h:84
static void m0_atomic64_dec(struct m0_atomic64 *a)
Definition: atomic64.h:57
atomic64_t a_value
Definition: atomic64.h:38
static void m0_mb(void)
Definition: atomic64.h:99
int num
Definition: bulk_if.c:54
static void m0_atomic64_set(struct m0_atomic64 *a, int64_t num)
Definition: atomic64.h:41