Motr  M0
mutex.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 
23 #pragma once
24 
25 #ifndef __MOTR_LIB_MUTEX_H__
26 #define __MOTR_LIB_MUTEX_H__
27 
28 #include "lib/types.h"
29 #include "addb2/histogram.h"
30 
36 #ifndef __KERNEL__
37 #include "lib/user_space/mutex.h"
38 #else
39 #include "lib/linux_kernel/mutex.h"
40 #endif
41 
42 /* struct m0_arch_mutex is defined by headers above. */
43 
44 struct m0_mutex_addb2;
45 struct m0_thread;
46 
47 struct m0_mutex {
49  struct m0_thread *m_owner;
51 };
52 
63 #define M0_MUTEX_SINIT(m) { .m_arch = M0_ARCH_MUTEX_SINIT((m)->m_arch) }
64 
65 M0_INTERNAL void m0_mutex_init(struct m0_mutex *mutex);
66 M0_INTERNAL void m0_mutex_fini(struct m0_mutex *mutex);
67 
74 M0_INTERNAL void m0_mutex_lock(struct m0_mutex *mutex);
75 
82 M0_INTERNAL void m0_mutex_unlock(struct m0_mutex *mutex);
83 
89 M0_INTERNAL int m0_mutex_trylock(struct m0_mutex *mutex);
90 
91 
97 M0_INTERNAL bool m0_mutex_is_locked(const struct m0_mutex *mutex);
98 
104 M0_INTERNAL bool m0_mutex_is_not_locked(const struct m0_mutex *mutex);
105 
110  uint64_t ma_id;
111 };
112 
113 /*
114  * Arch functions, implemented in lib/$ARCH/?mutex.c.
115  */
116 
117 M0_INTERNAL void m0_arch_mutex_init (struct m0_arch_mutex *mutex);
118 M0_INTERNAL void m0_arch_mutex_fini (struct m0_arch_mutex *mutex);
119 M0_INTERNAL void m0_arch_mutex_lock (struct m0_arch_mutex *mutex);
120 M0_INTERNAL void m0_arch_mutex_unlock (struct m0_arch_mutex *mutex);
121 M0_INTERNAL int m0_arch_mutex_trylock(struct m0_arch_mutex *mutex);
122 
125 /* __MOTR_LIB_MUTEX_H__ */
126 #endif
127 
128 /*
129  * Local variables:
130  * c-indentation-style: "K&R"
131  * c-basic-offset: 8
132  * tab-width: 8
133  * fill-column: 80
134  * scroll-step: 1
135  * End:
136  */
M0_INTERNAL int m0_mutex_trylock(struct m0_mutex *mutex)
Definition: mutex.c:84
M0_INTERNAL void m0_mutex_unlock(struct m0_mutex *mutex)
Definition: mutex.c:66
m0_time_t ma_taken
Definition: mutex.h:107
uint64_t m0_time_t
Definition: time.h:37
M0_INTERNAL bool m0_mutex_is_not_locked(const struct m0_mutex *mutex)
Definition: mutex.c:101
M0_INTERNAL void m0_mutex_lock(struct m0_mutex *mutex)
Definition: mutex.c:49
struct m0_addb2_hist ma_hold
Definition: mutex.h:108
M0_INTERNAL void m0_arch_mutex_init(struct m0_arch_mutex *mutex)
Definition: mutex.c:38
M0_INTERNAL bool m0_mutex_is_locked(const struct m0_mutex *mutex)
Definition: mutex.c:95
M0_INTERNAL void m0_arch_mutex_lock(struct m0_arch_mutex *mutex)
Definition: mutex.c:50
uint64_t ma_id
Definition: mutex.h:110
M0_INTERNAL void m0_mutex_init(struct m0_mutex *mutex)
Definition: mutex.c:35
struct m0_mutex_addb2 * m_addb2
Definition: mutex.h:50
struct m0_arch_mutex m_arch
Definition: mutex.h:48
struct m0_mutex mutex
Definition: format.h:170
M0_INTERNAL void m0_mutex_fini(struct m0_mutex *mutex)
Definition: mutex.c:42
M0_INTERNAL void m0_arch_mutex_unlock(struct m0_arch_mutex *mutex)
Definition: mutex.c:61
struct m0_addb2_hist ma_wait
Definition: mutex.h:109
Definition: mutex.h:47
M0_INTERNAL int m0_arch_mutex_trylock(struct m0_arch_mutex *mutex)
Definition: mutex.c:56
struct m0_thread * m_owner
Definition: mutex.h:49
M0_INTERNAL void m0_arch_mutex_fini(struct m0_arch_mutex *mutex)
Definition: mutex.c:44