Skip to content

Commit

Permalink
Add simple non-recursive readrs/writer lock
Browse files Browse the repository at this point in the history
Signed-off-by: Quincey Koziol <[email protected]>
  • Loading branch information
qkoziol committed May 13, 2024
1 parent edec810 commit 67089c4
Show file tree
Hide file tree
Showing 4 changed files with 575 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ set (H5TS_SOURCES
${HDF5_SRC_DIR}/H5TSpool.c
${HDF5_SRC_DIR}/H5TSpthread.c
${HDF5_SRC_DIR}/H5TSrec_rwlock.c
${HDF5_SRC_DIR}/H5TSrwlock.c
${HDF5_SRC_DIR}/H5TSthread.c
${HDF5_SRC_DIR}/H5TSwin.c
)
Expand Down
18 changes: 18 additions & 0 deletions src/H5TSprivate.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ typedef struct H5TS_pool_t H5TS_pool_t;

/* Portability aliases */
#ifdef H5_HAVE_C11_THREADS

/* Non-recursive readers/writer lock */
typedef struct H5TS_rwlock_t {
mtx_t mutex;
cnd_t read_cv, write_cv;
unsigned readers, writers, read_waiters, write_waiters;
} H5TS_rwlock_t;

typedef thrd_t H5TS_thread_t;
typedef int (*H5TS_thread_start_func_t)(void *);
typedef int H5TS_thread_ret_t;
Expand All @@ -131,6 +139,7 @@ typedef LPTHREAD_START_ROUTINE H5TS_thread_start_func_t;
typedef DWORD H5TS_thread_ret_t;
typedef DWORD H5TS_key_t;
typedef CRITICAL_SECTION H5TS_CAPABILITY("mutex") H5TS_mutex_t;
typedef SRWLOCK H5TS_rwlock_t;
typedef CONDITION_VARIABLE H5TS_cond_t;
typedef INIT_ONCE H5TS_once_t;
typedef PINIT_ONCE_FN H5TS_once_init_func_t;
Expand All @@ -140,6 +149,7 @@ typedef void *(*H5TS_thread_start_func_t)(void *);
typedef void *H5TS_thread_ret_t;
typedef pthread_key_t H5TS_key_t;
typedef pthread_mutex_t H5TS_CAPABILITY("mutex") H5TS_mutex_t;
typedef pthread_rwlock_t H5TS_rwlock_t;
typedef pthread_cond_t H5TS_cond_t;
typedef pthread_once_t H5TS_once_t;
typedef void (*H5TS_once_init_func_t)(void);
Expand Down Expand Up @@ -206,6 +216,14 @@ H5_DLL herr_t H5TS_mutex_trylock(H5TS_mutex_t *mutex, bool *acquired) H5TS_TRY_A
H5_DLL herr_t H5TS_mutex_unlock(H5TS_mutex_t *mutex) H5TS_RELEASE(*mutex);
H5_DLL herr_t H5TS_mutex_destroy(H5TS_mutex_t *mutex);

/* R/W locks */
H5_DLL herr_t H5TS_rwlock_init(H5TS_rwlock_t *lock);
H5_DLL herr_t H5TS_rwlock_rdlock(H5TS_rwlock_t *lock);
H5_DLL herr_t H5TS_rwlock_rdunlock(H5TS_rwlock_t *lock);
H5_DLL herr_t H5TS_rwlock_wrlock(H5TS_rwlock_t *lock);
H5_DLL herr_t H5TS_rwlock_wrunlock(H5TS_rwlock_t *lock);
H5_DLL herr_t H5TS_rwlock_destroy(H5TS_rwlock_t *lock);

/* Condition variable operations */
H5_DLL herr_t H5TS_cond_init(H5TS_cond_t *cond);
H5_DLL herr_t H5TS_cond_wait(H5TS_cond_t *cond, H5TS_mutex_t *mutex);
Expand Down
Loading

0 comments on commit 67089c4

Please sign in to comment.