]>
Commit | Line | Data |
---|---|---|
de8ee011 A |
1 | /* Copyright © 2017-2018 Apple Inc. All rights reserved. |
2 | * | |
3 | * lf_hfs_locks.h | |
4 | * livefiles_hfs | |
5 | * | |
6 | * Created by Or Haimovich on 18/3/18. | |
7 | */ | |
8 | ||
9 | #ifndef lf_hfs_locks_h | |
10 | #define lf_hfs_locks_h | |
11 | ||
12 | #include <stdio.h> | |
13 | #include <stdint.h> | |
14 | #include <stdbool.h> | |
15 | #include <pthread.h> | |
16 | ||
17 | typedef enum | |
18 | { | |
19 | LCK_RW_TYPE_SHARED, | |
20 | LCK_RW_TYPE_EXCLUSIVE | |
21 | ||
22 | } lck_rwlock_type_e; | |
23 | ||
24 | typedef uint8_t lck_attr_t; | |
25 | typedef uint8_t lck_grp_attr_t; | |
26 | typedef uint8_t lck_grp_t; | |
27 | ||
28 | // Read/Write locks. | |
29 | void lf_lck_rw_init ( pthread_rwlock_t* lck ); | |
30 | void lf_lck_rw_destroy ( pthread_rwlock_t* lck ); | |
31 | void lf_lck_rw_unlock_shared ( pthread_rwlock_t* lck ); | |
32 | void lf_lck_rw_lock_shared ( pthread_rwlock_t* lck ); | |
33 | void lf_lck_rw_lock_exclusive ( pthread_rwlock_t* lck ); | |
34 | void lf_lck_rw_unlock_exclusive ( pthread_rwlock_t* lck ); | |
35 | bool lf_lck_rw_try_lock ( pthread_rwlock_t* lck, lck_rwlock_type_e which ); | |
36 | void lf_lck_rw_lock_exclusive_to_shared ( pthread_rwlock_t* lck); | |
37 | bool lf_lck_rw_lock_shared_to_exclusive ( pthread_rwlock_t* lck); | |
38 | ||
39 | // Mutex locks. | |
40 | void lf_lck_mtx_init ( pthread_mutex_t* lck ); | |
41 | void lf_lck_mtx_destroy ( pthread_mutex_t *lck ); | |
42 | void lf_lck_mtx_lock ( pthread_mutex_t* lck ); | |
43 | void lf_lck_mtx_unlock ( pthread_mutex_t* lck ); | |
44 | void lf_lck_mtx_lock_spin ( pthread_mutex_t *lck ); | |
45 | int lf_lck_mtx_try_lock ( pthread_mutex_t *lck ); | |
46 | void lf_lck_mtx_convert_spin ( pthread_mutex_t *lck ); | |
47 | ||
48 | //Cond | |
49 | void lf_cond_destroy( pthread_cond_t* cond ); | |
50 | void lf_cond_init( pthread_cond_t* cond ); | |
51 | int lf_cond_wait_relative(pthread_cond_t *pCond, pthread_mutex_t *pMutex, struct timespec *pTime); | |
52 | void lf_cond_wakeup(pthread_cond_t *pCond); | |
53 | ||
54 | // Spin locks. | |
55 | void lf_lck_spin_init ( pthread_mutex_t *lck ); | |
56 | void lf_lck_spin_destroy ( pthread_mutex_t *lck ); | |
57 | void lf_lck_spin_lock ( pthread_mutex_t *lck ); | |
58 | void lf_lck_spin_unlock ( pthread_mutex_t *lck ); | |
59 | ||
60 | // Init | |
61 | lck_attr_t *lf_lck_attr_alloc_init ( void ); | |
62 | lck_grp_attr_t *lf_lck_grp_attr_alloc_init ( void ); | |
63 | lck_grp_t *lf_lck_grp_alloc_init ( void ); | |
64 | ||
65 | #endif /* lf_hfs_locks_h */ |