]> git.saurik.com Git - apple/hfs.git/blame - livefiles_hfs_plugin/lf_hfs_locks.c
hfs-556.100.11.tar.gz
[apple/hfs.git] / livefiles_hfs_plugin / lf_hfs_locks.c
CommitLineData
de8ee011
A
1/* Copyright © 2017-2018 Apple Inc. All rights reserved.
2 *
3 * lf_hfs_locks.c
4 * livefiles_hfs
5 *
6 * Created by Or Haimovich on 18/3/18.
7 */
8
9#include "lf_hfs_locks.h"
10#include <errno.h>
11#include <assert.h>
12
13void lf_lck_rw_init( pthread_rwlock_t* lck )
14{
15 errno_t err = pthread_rwlock_init( lck, NULL );
16 assert( err == 0 );
17}
18
19void lf_lck_rw_destroy( pthread_rwlock_t* lck )
20{
21 errno_t err = pthread_rwlock_destroy( lck );
22 assert( err == 0 );
23}
24
25void lf_lck_rw_unlock_shared( pthread_rwlock_t* lck )
26{
27 errno_t err = pthread_rwlock_unlock( lck );
28 assert( err == 0 );
29}
30
31void lf_lck_rw_lock_shared( pthread_rwlock_t* lck )
32{
33 errno_t err = pthread_rwlock_rdlock( lck );
34 assert( err == 0 );
35}
36
37void lf_lck_rw_lock_exclusive( pthread_rwlock_t* lck )
38{
39 errno_t err = pthread_rwlock_wrlock( lck );
40 assert( err == 0 );
41}
42
43void lf_lck_rw_unlock_exclusive( pthread_rwlock_t* lck )
44{
45 errno_t err = pthread_rwlock_unlock( lck );
46 assert( err == 0 );
47}
48
49bool lf_lck_rw_try_lock( pthread_rwlock_t* lck, lck_rwlock_type_e which )
50{
51 bool trylock;
52
53 if ( which == LCK_RW_TYPE_SHARED )
54 {
55 trylock = pthread_rwlock_tryrdlock( lck );
56 }
57 else if ( which == LCK_RW_TYPE_EXCLUSIVE )
58 {
59 trylock = pthread_rwlock_trywrlock( lck );
60 }
61 else
62 {
63 assert(0);
64 }
65
66 return trylock;
67}
68
69void lf_lck_rw_lock_exclusive_to_shared( pthread_rwlock_t* lck)
70{
71 lf_lck_rw_unlock_exclusive( lck );
72 lf_lck_rw_lock_shared( lck );
73}
74
75bool lf_lck_rw_lock_shared_to_exclusive( pthread_rwlock_t* lck)
76{
77 lf_lck_rw_unlock_shared( lck );
78 lf_lck_rw_lock_exclusive( lck );
79
80 return true;
81}
82
83void lf_cond_init( pthread_cond_t* cond )
84{
85 errno_t err = pthread_cond_init( cond, NULL );
86 assert( err == 0 );
87}
88
89void lf_cond_destroy( pthread_cond_t* cond )
90{
91 errno_t err = pthread_cond_destroy( cond );
92 assert( err == 0 );
93}
94
95int lf_cond_wait_relative(pthread_cond_t *pCond, pthread_mutex_t *pMutex, struct timespec *pTime) {
96
97 int iErr = pthread_cond_timedwait_relative_np(pCond, pMutex, pTime);
98 assert((iErr == 0) || (iErr == ETIMEDOUT));
99 return(iErr);
100}
101
102void lf_cond_wakeup(pthread_cond_t *pCond) {
103
104 int iErr = pthread_cond_signal(pCond);
105 assert(iErr == 0);
106}
107
108void lf_lck_mtx_init( pthread_mutex_t* lck )
109{
110 errno_t err = pthread_mutex_init( lck, NULL );
111 assert( err == 0 );
112}
113
114void lf_lck_mtx_destroy( pthread_mutex_t *lck )
115{
116 errno_t err = pthread_mutex_destroy( lck );
117 assert( err == 0 );
118}
119
120void lf_lck_mtx_lock( pthread_mutex_t* lck )
121{
122 errno_t err = pthread_mutex_lock( lck );
123 assert( err == 0 );
124}
125
126void lf_lck_mtx_unlock( pthread_mutex_t* lck )
127{
128 errno_t err = pthread_mutex_unlock( lck );
129 assert( err == 0 );
130}
131
132void lf_lck_mtx_lock_spin( pthread_mutex_t *lck )
133{
134 // No real spin lock
135 lf_lck_mtx_lock( lck );
136}
137
138int lf_lck_mtx_try_lock(pthread_mutex_t *lck) {
139 errno_t err = pthread_mutex_trylock(lck);
140 return err;
141}
142
143//void lf_lck_mtx_convert_spin( pthread_mutex_t *lck )
144//{
145// // No real spin lock
146//}
147
148void lf_lck_spin_init( pthread_mutex_t *lck )
149{
150 errno_t err = pthread_mutex_init( lck, NULL );
151 assert( err == 0 );
152}
153
154void lf_lck_spin_destroy( pthread_mutex_t *lck )
155{
156 errno_t err = pthread_mutex_destroy( lck );
157 assert( err == 0 );
158}
159
160void lf_lck_spin_lock( pthread_mutex_t *lck )
161{
162 errno_t err = pthread_mutex_lock( lck );
163 assert( err == 0 );
164}
165
166void lf_lck_spin_unlock( pthread_mutex_t *lck )
167{
168 errno_t err = pthread_mutex_unlock( lck );
169 assert( err == 0 );
170}
171
172lck_attr_t *lf_lck_attr_alloc_init( void )
173{
174 static lck_attr_t attr = {0};
175 return &attr;
176}
177lck_grp_attr_t *lf_lck_grp_attr_alloc_init( void )
178{
179 static lck_grp_attr_t group_attr = {0};
180 return &group_attr;
181}
182lck_grp_t *lf_lck_grp_alloc_init( void )
183{
184 static lck_grp_t group = {0};
185 return &group;
186}