1 /* Copyright © 2017-2018 Apple Inc. All rights reserved.
6 * Created by Or Haimovich on 18/3/18.
9 #include "lf_hfs_locks.h"
13 void lf_lck_rw_init( pthread_rwlock_t
* lck
)
15 errno_t err
= pthread_rwlock_init( lck
, NULL
);
19 void lf_lck_rw_destroy( pthread_rwlock_t
* lck
)
21 errno_t err
= pthread_rwlock_destroy( lck
);
25 void lf_lck_rw_unlock_shared( pthread_rwlock_t
* lck
)
27 errno_t err
= pthread_rwlock_unlock( lck
);
31 void lf_lck_rw_lock_shared( pthread_rwlock_t
* lck
)
33 errno_t err
= pthread_rwlock_rdlock( lck
);
37 void lf_lck_rw_lock_exclusive( pthread_rwlock_t
* lck
)
39 errno_t err
= pthread_rwlock_wrlock( lck
);
43 void lf_lck_rw_unlock_exclusive( pthread_rwlock_t
* lck
)
45 errno_t err
= pthread_rwlock_unlock( lck
);
49 bool lf_lck_rw_try_lock( pthread_rwlock_t
* lck
, lck_rwlock_type_e which
)
53 if ( which
== LCK_RW_TYPE_SHARED
)
55 trylock
= pthread_rwlock_tryrdlock( lck
);
57 else if ( which
== LCK_RW_TYPE_EXCLUSIVE
)
59 trylock
= pthread_rwlock_trywrlock( lck
);
69 void lf_lck_rw_lock_exclusive_to_shared( pthread_rwlock_t
* lck
)
71 lf_lck_rw_unlock_exclusive( lck
);
72 lf_lck_rw_lock_shared( lck
);
75 bool lf_lck_rw_lock_shared_to_exclusive( pthread_rwlock_t
* lck
)
77 lf_lck_rw_unlock_shared( lck
);
78 lf_lck_rw_lock_exclusive( lck
);
83 void lf_cond_init( pthread_cond_t
* cond
)
85 errno_t err
= pthread_cond_init( cond
, NULL
);
89 void lf_cond_destroy( pthread_cond_t
* cond
)
91 errno_t err
= pthread_cond_destroy( cond
);
95 int lf_cond_wait_relative(pthread_cond_t
*pCond
, pthread_mutex_t
*pMutex
, struct timespec
*pTime
) {
97 int iErr
= pthread_cond_timedwait_relative_np(pCond
, pMutex
, pTime
);
98 assert((iErr
== 0) || (iErr
== ETIMEDOUT
));
102 void lf_cond_wakeup(pthread_cond_t
*pCond
) {
104 int iErr
= pthread_cond_signal(pCond
);
108 void lf_lck_mtx_init( pthread_mutex_t
* lck
)
110 errno_t err
= pthread_mutex_init( lck
, NULL
);
114 void lf_lck_mtx_destroy( pthread_mutex_t
*lck
)
116 errno_t err
= pthread_mutex_destroy( lck
);
120 void lf_lck_mtx_lock( pthread_mutex_t
* lck
)
122 errno_t err
= pthread_mutex_lock( lck
);
126 void lf_lck_mtx_unlock( pthread_mutex_t
* lck
)
128 errno_t err
= pthread_mutex_unlock( lck
);
132 void lf_lck_mtx_lock_spin( pthread_mutex_t
*lck
)
135 lf_lck_mtx_lock( lck
);
138 int lf_lck_mtx_try_lock(pthread_mutex_t
*lck
) {
139 errno_t err
= pthread_mutex_trylock(lck
);
143 //void lf_lck_mtx_convert_spin( pthread_mutex_t *lck )
145 // // No real spin lock
148 void lf_lck_spin_init( pthread_mutex_t
*lck
)
150 errno_t err
= pthread_mutex_init( lck
, NULL
);
154 void lf_lck_spin_destroy( pthread_mutex_t
*lck
)
156 errno_t err
= pthread_mutex_destroy( lck
);
160 void lf_lck_spin_lock( pthread_mutex_t
*lck
)
162 errno_t err
= pthread_mutex_lock( lck
);
166 void lf_lck_spin_unlock( pthread_mutex_t
*lck
)
168 errno_t err
= pthread_mutex_unlock( lck
);
172 lck_attr_t
*lf_lck_attr_alloc_init( void )
174 static lck_attr_t attr
= {0};
177 lck_grp_attr_t
*lf_lck_grp_attr_alloc_init( void )
179 static lck_grp_attr_t group_attr
= {0};
182 lck_grp_t
*lf_lck_grp_alloc_init( void )
184 static lck_grp_t group
= {0};