aboutsummaryrefslogtreecommitdiff
path: root/src/sp
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2021-07-11 13:03:54 -0700
committerGarrett D'Amore <garrett@damore.org>2021-07-11 13:04:28 -0700
commitca41e1c52a2264a63dcf6604a49e29b1d4a221c6 (patch)
tree4972c47d609594c596c2383b8ad2aaa2615a6962 /src/sp
parent9fcf039b573d153ba9bbc2beb5f11259ddacdcff (diff)
downloadnng-ca41e1c52a2264a63dcf6604a49e29b1d4a221c6.tar.gz
nng-ca41e1c52a2264a63dcf6604a49e29b1d4a221c6.tar.bz2
nng-ca41e1c52a2264a63dcf6604a49e29b1d4a221c6.zip
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.
Diffstat (limited to 'src/sp')
-rw-r--r--src/sp/transport.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/src/sp/transport.c b/src/sp/transport.c
index f8751f68..7f76af16 100644
--- a/src/sp/transport.c
+++ b/src/sp/transport.c
@@ -43,9 +43,9 @@ typedef struct nni_sp_transport {
nni_list_node t_node;
} nni_sp_transport;
-static nni_list nni_sp_tran_list;
-static nni_mtx nni_sp_tran_lk;
-static int nni_sp_tran_inited;
+static nni_list nni_sp_tran_list;
+static nni_rwlock nni_sp_tran_lk;
+static int nni_sp_tran_inited;
int
nni_sp_tran_register(const nni_sp_tran *tran)
@@ -65,32 +65,32 @@ nni_sp_tran_register(const nni_sp_tran *tran)
return (NNG_ENOTSUP);
}
- nni_mtx_lock(&nni_sp_tran_lk);
+ nni_rwlock_wrlock(&nni_sp_tran_lk);
// Check to see if the transport is already registered...
NNI_LIST_FOREACH (&nni_sp_tran_list, t) {
if (strcmp(tran->tran_scheme, t->t_tran.tran_scheme) == 0) {
if (tran->tran_init == t->t_tran.tran_init) {
// duplicate.
- nni_mtx_unlock(&nni_sp_tran_lk);
+ nni_rwlock_unlock(&nni_sp_tran_lk);
return (0);
}
- nni_mtx_unlock(&nni_sp_tran_lk);
+ nni_rwlock_unlock(&nni_sp_tran_lk);
return (NNG_ESTATE);
}
}
if ((t = NNI_ALLOC_STRUCT(t)) == NULL) {
- nni_mtx_unlock(&nni_sp_tran_lk);
+ nni_rwlock_unlock(&nni_sp_tran_lk);
return (NNG_ENOMEM);
}
t->t_tran = *tran;
if ((rv = t->t_tran.tran_init()) != 0) {
- nni_mtx_unlock(&nni_sp_tran_lk);
+ nni_rwlock_unlock(&nni_sp_tran_lk);
NNI_FREE_STRUCT(t);
return (rv);
}
nni_list_append(&nni_sp_tran_list, t);
- nni_mtx_unlock(&nni_sp_tran_lk);
+ nni_rwlock_unlock(&nni_sp_tran_lk);
return (0);
}
@@ -100,14 +100,14 @@ nni_sp_tran_find(nni_url *url)
// address is of the form "<scheme>://blah..."
nni_sp_transport *t;
- nni_mtx_lock(&nni_sp_tran_lk);
+ nni_rwlock_rdlock(&nni_sp_tran_lk);
NNI_LIST_FOREACH (&nni_sp_tran_list, t) {
if (strcmp(url->u_scheme, t->t_tran.tran_scheme) == 0) {
- nni_mtx_unlock(&nni_sp_tran_lk);
+ nni_rwlock_unlock(&nni_sp_tran_lk);
return (&t->t_tran);
}
}
- nni_mtx_unlock(&nni_sp_tran_lk);
+ nni_rwlock_unlock(&nni_sp_tran_lk);
return (NULL);
}
@@ -150,7 +150,7 @@ nni_sp_tran_sys_init(void)
nni_sp_tran_inited = 1;
NNI_LIST_INIT(&nni_sp_tran_list, nni_sp_transport, t_node);
- nni_mtx_init(&nni_sp_tran_lk);
+ nni_rwlock_init(&nni_sp_tran_lk);
for (i = 0; nni_sp_tran_ctors[i] != NULL; i++) {
int rv;
@@ -174,6 +174,6 @@ nni_sp_tran_sys_fini(void)
t->t_tran.tran_fini();
NNI_FREE_STRUCT(t);
}
- nni_mtx_fini(&nni_sp_tran_lk);
+ nni_rwlock_fini(&nni_sp_tran_lk);
nni_sp_tran_inited = 0;
}