Motr  M0
umutex.c
Go to the documentation of this file.
1 /* -*- C -*- */
2 /*
3  * Copyright (c) 2011-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 #include "lib/misc.h" /* M0_SET0 */
24 #include "lib/mutex.h"
25 #include "lib/assert.h"
26 #include "lib/errno.h" /* EBUSY */
27 
36 M0_INTERNAL void m0_arch_mutex_init(struct m0_arch_mutex *mutex)
37 {
38  int rc;
39 
40  rc = pthread_mutex_init(&mutex->m_impl, NULL);
41  M0_ASSERT_INFO(rc == 0, "rc=%d", rc);
42 }
43 
44 M0_INTERNAL void m0_arch_mutex_fini(struct m0_arch_mutex *mutex)
45 {
46  int rc;
47 
48  rc = pthread_mutex_destroy(&mutex->m_impl);
49  M0_ASSERT_INFO(rc == 0, "rc=%d", rc);
50 }
51 
52 M0_INTERNAL void m0_arch_mutex_lock(struct m0_arch_mutex *mutex)
53 {
54  int rc;
55 
56  rc = pthread_mutex_lock(&mutex->m_impl);
57  M0_ASSERT_INFO(rc == 0, "rc=%d", rc);
58 }
59 
60 M0_INTERNAL void m0_arch_mutex_unlock(struct m0_arch_mutex *mutex)
61 {
62  int rc;
63 
64  rc = pthread_mutex_unlock(&mutex->m_impl);
65  M0_ASSERT_INFO(rc == 0, "rc=%d", rc);
66 }
67 
68 M0_INTERNAL int m0_arch_mutex_trylock(struct m0_arch_mutex *mutex)
69 {
70  int rc;
71 
72  rc = pthread_mutex_trylock(&mutex->m_impl);
73  M0_ASSERT_INFO(M0_IN(rc, (0, EBUSY)), "rc=%d", rc);
74  return rc;
75 }
76 
79 /*
80  * Local variables:
81  * c-indentation-style: "K&R"
82  * c-basic-offset: 8
83  * tab-width: 8
84  * fill-column: 80
85  * scroll-step: 1
86  * End:
87  */
#define NULL
Definition: misc.h:38
M0_INTERNAL void m0_arch_mutex_init(struct m0_arch_mutex *mutex)
Definition: mutex.c:38
M0_INTERNAL void m0_arch_mutex_lock(struct m0_arch_mutex *mutex)
Definition: mutex.c:50
struct m0_mutex mutex
Definition: format.h:170
M0_INTERNAL void m0_arch_mutex_unlock(struct m0_arch_mutex *mutex)
Definition: mutex.c:61
#define M0_ASSERT_INFO(cond, fmt,...)
M0_INTERNAL int m0_arch_mutex_trylock(struct m0_arch_mutex *mutex)
Definition: mutex.c:56
int32_t rc
Definition: trigger_fop.h:47
M0_INTERNAL void m0_arch_mutex_fini(struct m0_arch_mutex *mutex)
Definition: mutex.c:44