From e5d5b625f16c3c3df5a3fdcc114a6694d82ab6e8 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Sun, 5 Jan 2025 09:46:16 -0800 Subject: platform: remove reader/writer locks The only thing using this was the transport lookups, but as those transports are now fully initialized in nng_init, we no longer need to lock that at all. --- src/platform/posix/posix_impl.h | 9 -------- src/platform/posix/posix_thread.c | 47 --------------------------------------- src/platform/windows/win_impl.h | 10 --------- src/platform/windows/win_thread.c | 38 +------------------------------ 4 files changed, 1 insertion(+), 103 deletions(-) (limited to 'src/platform') diff --git a/src/platform/posix/posix_impl.h b/src/platform/posix/posix_impl.h index b6435353..2229f17c 100644 --- a/src/platform/posix/posix_impl.h +++ b/src/platform/posix/posix_impl.h @@ -65,15 +65,6 @@ struct nni_plat_mtx { PTHREAD_MUTEX_INITIALIZER \ } -struct nni_rwlock { - pthread_rwlock_t rwl; -}; - -#define NNI_RWLOCK_INITIALIZER \ - { \ - PTHREAD_RWLOCK_INITIALIZER \ - } - // No static form of CV initialization because of the need to use // attributes to set the clock type. struct nni_plat_cv { diff --git a/src/platform/posix/posix_thread.c b/src/platform/posix/posix_thread.c index e8c9036c..ac6371c9 100644 --- a/src/platform/posix/posix_thread.c +++ b/src/platform/posix/posix_thread.c @@ -155,53 +155,6 @@ nni_plat_mtx_unlock(nni_plat_mtx *mtx) nni_pthread_mutex_unlock(&mtx->mtx); } -void -nni_rwlock_init(nni_rwlock *rwl) -{ - while (pthread_rwlock_init(&rwl->rwl, NULL) != 0) { - // We must have memory exhaustion -- ENOMEM, or - // in some cases EAGAIN. Wait a bit before we try to - // give things a chance to settle down. - nni_msleep(10); - } -} - -void -nni_rwlock_fini(nni_rwlock *rwl) -{ - int rv; - if ((rv = pthread_rwlock_destroy(&rwl->rwl)) != 0) { - nni_panic("pthread_rwlock_destroy: %s", strerror(rv)); - } -} - -void -nni_rwlock_rdlock(nni_rwlock *rwl) -{ - int rv; - if ((rv = pthread_rwlock_rdlock(&rwl->rwl)) != 0) { - nni_panic("pthread_rwlock_rdlock: %s", strerror(rv)); - } -} - -void -nni_rwlock_wrlock(nni_rwlock *rwl) -{ - int rv; - if ((rv = pthread_rwlock_wrlock(&rwl->rwl)) != 0) { - nni_panic("pthread_rwlock_wrlock: %s", strerror(rv)); - } -} - -void -nni_rwlock_unlock(nni_rwlock *rwl) -{ - int rv; - if ((rv = pthread_rwlock_unlock(&rwl->rwl)) != 0) { - nni_panic("pthread_rwlock_unlock: %s", strerror(rv)); - } -} - void nni_plat_cv_init(nni_plat_cv *cv, nni_plat_mtx *mtx) { diff --git a/src/platform/windows/win_impl.h b/src/platform/windows/win_impl.h index 1659b099..db190d42 100644 --- a/src/platform/windows/win_impl.h +++ b/src/platform/windows/win_impl.h @@ -44,16 +44,6 @@ struct nni_plat_mtx { SRWLOCK_INIT \ } -struct nni_rwlock { - SRWLOCK rwl; - BOOLEAN exclusive; -}; - -#define NNI_RWLOCK_INITIALIZER \ - { \ - SRWLOCK_INIT \ - } - struct nni_plat_cv { CONDITION_VARIABLE cv; PSRWLOCK srl; diff --git a/src/platform/windows/win_thread.c b/src/platform/windows/win_thread.c index c76209c1..7d865604 100644 --- a/src/platform/windows/win_thread.c +++ b/src/platform/windows/win_thread.c @@ -1,5 +1,5 @@ // -// Copyright 2024 Staysail Systems, Inc. +// Copyright 2025 Staysail Systems, Inc. // Copyright 2018 Capitar IT Group BV // // This software is supplied under the terms of the MIT License, a @@ -78,42 +78,6 @@ nni_plat_mtx_unlock(nni_plat_mtx *mtx) ReleaseSRWLockExclusive(&mtx->srl); } -void -nni_rwlock_init(nni_rwlock *rwl) -{ - InitializeSRWLock(&rwl->rwl); -} - -void -nni_rwlock_fini(nni_rwlock *rwl) -{ - rwl->exclusive = FALSE; -} - -void -nni_rwlock_rdlock(nni_rwlock *rwl) -{ - AcquireSRWLockShared(&rwl->rwl); -} - -void -nni_rwlock_wrlock(nni_rwlock *rwl) -{ - AcquireSRWLockExclusive(&rwl->rwl); - rwl->exclusive = TRUE; -} - -void -nni_rwlock_unlock(nni_rwlock *rwl) -{ - if (rwl->exclusive) { - rwl->exclusive = FALSE; - ReleaseSRWLockExclusive(&rwl->rwl); - } else { - ReleaseSRWLockShared(&rwl->rwl); - } -} - void nni_plat_cv_init(nni_plat_cv *cv, nni_plat_mtx *mtx) { -- cgit v1.2.3-70-g09d2