From ca41e1c52a2264a63dcf6604a49e29b1d4a221c6 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sun, 11 Jul 2021 13:03:54 -0700 Subject: fixes #1409 reader/writer lock desired This provides the initial implementation, and converts the transport lookup routines to use it. This is probably of limited performance benefit, but rwlock's may be useful in further future work. --- src/core/platform.h | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) (limited to 'src/core') diff --git a/src/core/platform.h b/src/core/platform.h index 35d42339..5739811f 100644 --- a/src/core/platform.h +++ b/src/core/platform.h @@ -1,5 +1,5 @@ // -// Copyright 2020 Staysail Systems, Inc. +// Copyright 2021 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // Copyright 2018 Devolutions // @@ -88,9 +88,11 @@ extern void *nni_zalloc(size_t); // Most implementations can just call free() here. extern void nni_free(void *, size_t); -typedef struct nni_plat_mtx nni_plat_mtx; -typedef struct nni_plat_cv nni_plat_cv; -typedef struct nni_plat_thr nni_plat_thr; +typedef struct nni_plat_mtx nni_plat_mtx; +typedef struct nni_plat_rwlock nni_plat_rwlock; +typedef struct nni_plat_cv nni_plat_cv; +typedef struct nni_plat_thr nni_plat_thr; +typedef struct nni_rwlock nni_rwlock; // // Threading & Synchronization Support @@ -112,6 +114,15 @@ extern void nni_plat_mtx_lock(nni_plat_mtx *); // thread that owned the mutex. extern void nni_plat_mtx_unlock(nni_plat_mtx *); +// read/write locks - these work like mutexes except that multiple readers +// can acquire the lock. These are not safe for recursive use, and it is +// unspecified whether any measures are provided to prevent starvation. +extern void nni_rwlock_init(nni_rwlock *); +extern void nni_rwlock_fini(nni_rwlock *); +extern void nni_rwlock_rdlock(nni_rwlock *); +extern void nni_rwlock_wrlock(nni_rwlock *); +extern void nni_rwlock_unlock(nni_rwlock *); + // nni_plat_cv_init initializes a condition variable. We require a mutex be // supplied with it, and that mutex must always be held when performing any // operations on the condition variable (other than fini.) As with mutexes, an @@ -161,6 +172,7 @@ extern bool nni_plat_thr_is_self(nni_plat_thr *); // should be a short ASCII string. It may or may not be supported -- // this is intended to facilitate debugging. extern void nni_plat_thr_set_name(nni_plat_thr *, const char *); + // // Atomics support. This will evolve over time. // -- cgit v1.2.3-70-g09d2