aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/core/reap.c18
-rw-r--r--src/platform/posix/posix_impl.h5
-rw-r--r--src/platform/posix/posix_resolv_gai.c33
-rw-r--r--src/platform/windows/win_impl.h2
-rw-r--r--src/platform/windows/win_resolv.c14
5 files changed, 31 insertions, 41 deletions
diff --git a/src/core/reap.c b/src/core/reap.c
index 8be5ee12..3f182205 100644
--- a/src/core/reap.c
+++ b/src/core/reap.c
@@ -1,5 +1,5 @@
//
-// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2021 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2017 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
@@ -17,11 +17,11 @@
// New stuff.
static nni_reap_list *reap_list = NULL;
static nni_thr reap_thr;
-static bool reap_exit;
-static nni_mtx reap_mtx;
+static bool reap_exit = false;
+static nni_mtx reap_mtx = NNI_MTX_INITIALIZER;
static bool reap_empty;
-static nni_cv reap_work_cv;
-static nni_cv reap_empty_cv;
+static nni_cv reap_work_cv = NNI_CV_INITIALIZER(&reap_mtx);
+static nni_cv reap_empty_cv = NNI_CV_INITIALIZER(&reap_mtx);
static void
reap_worker(void *unused)
@@ -105,17 +105,9 @@ nni_reap_sys_init(void)
{
int rv;
- reap_exit = false;
- nni_mtx_init(&reap_mtx);
- nni_cv_init(&reap_work_cv, &reap_mtx);
- nni_cv_init(&reap_empty_cv, &reap_mtx);
-
// If this fails, we don't fail init, instead we will try to
// start up at reap time.
if ((rv = nni_thr_init(&reap_thr, reap_worker, NULL)) != 0) {
- nni_cv_fini(&reap_work_cv);
- nni_cv_fini(&reap_empty_cv);
- nni_mtx_fini(&reap_mtx);
return (rv);
}
nni_thr_run(&reap_thr);
diff --git a/src/platform/posix/posix_impl.h b/src/platform/posix/posix_impl.h
index 97924a45..0ee7cb38 100644
--- a/src/platform/posix/posix_impl.h
+++ b/src/platform/posix/posix_impl.h
@@ -73,6 +73,11 @@ struct nni_plat_cv {
nni_plat_mtx *mtx;
};
+// NOTE: condition variables initialized with this should *NOT*
+// be used with nni_cv_until -- the clock attributes are not passed
+// and the wake-up times will not be correct.
+#define NNI_CV_INITIALIZER(mxp) { .mtx = mxp, .cv = PTHREAD_COND_INITIALIZER }
+
struct nni_plat_thr {
pthread_t tid;
void (*func)(void *);
diff --git a/src/platform/posix/posix_resolv_gai.c b/src/platform/posix/posix_resolv_gai.c
index 83974b3d..aa6547a5 100644
--- a/src/platform/posix/posix_resolv_gai.c
+++ b/src/platform/posix/posix_resolv_gai.c
@@ -1,5 +1,5 @@
//
-// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2021 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
@@ -33,9 +33,9 @@
#define NNG_RESOLV_CONCURRENCY 4
#endif
-static nni_mtx resolv_mtx;
-static nni_cv resolv_cv;
-static bool resolv_fini;
+static nni_mtx resolv_mtx = NNI_MTX_INITIALIZER;
+static nni_cv resolv_cv = NNI_CV_INITIALIZER(&resolv_mtx);
+static bool resolv_fini = false;
static nni_list resolv_aios;
static nni_thr resolv_thrs[NNG_RESOLV_CONCURRENCY];
@@ -43,9 +43,9 @@ typedef struct resolv_item resolv_item;
struct resolv_item {
int family;
bool passive;
- char * host;
- char * serv;
- nni_aio * aio;
+ char *host;
+ char *serv;
+ nni_aio *aio;
nng_sockaddr *sa;
};
@@ -189,9 +189,9 @@ resolv_task(resolv_item *item)
nni_mtx_lock(&resolv_mtx);
if ((probe != NULL) && (item->aio != NULL)) {
- struct sockaddr_in * sin;
+ struct sockaddr_in *sin;
struct sockaddr_in6 *sin6;
- nng_sockaddr * sa = item->sa;
+ nng_sockaddr *sa = item->sa;
switch (probe->ai_addr->sa_family) {
case AF_INET:
@@ -301,7 +301,7 @@ resolv_worker(void *unused)
nni_mtx_lock(&resolv_mtx);
for (;;) {
- nni_aio * aio;
+ nni_aio *aio;
resolv_item *item;
int rv;
@@ -343,9 +343,9 @@ parse_ip(const char *addr, nng_sockaddr *sa, bool want_port)
int rv;
bool v6 = false;
bool wrapped = false;
- char * port;
- char * host;
- char * buf;
+ char *port;
+ char *host;
+ char *buf;
size_t buf_len;
if (addr == NULL) {
@@ -443,11 +443,8 @@ nni_parse_ip_port(const char *addr, nni_sockaddr *sa)
int
nni_posix_resolv_sysinit(void)
{
- nni_mtx_init(&resolv_mtx);
- nni_cv_init(&resolv_cv, &resolv_mtx);
- nni_aio_list_init(&resolv_aios);
-
resolv_fini = false;
+ nni_aio_list_init(&resolv_aios);
for (int i = 0; i < NNG_RESOLV_CONCURRENCY; i++) {
int rv = nni_thr_init(&resolv_thrs[i], resolv_worker, NULL);
@@ -474,8 +471,6 @@ nni_posix_resolv_sysfini(void)
for (int i = 0; i < NNG_RESOLV_CONCURRENCY; i++) {
nni_thr_fini(&resolv_thrs[i]);
}
- nni_cv_fini(&resolv_cv);
- nni_mtx_fini(&resolv_mtx);
}
#endif // NNG_USE_POSIX_RESOLV_GAI
diff --git a/src/platform/windows/win_impl.h b/src/platform/windows/win_impl.h
index b3c08edf..bbd007d0 100644
--- a/src/platform/windows/win_impl.h
+++ b/src/platform/windows/win_impl.h
@@ -53,6 +53,8 @@ struct nni_plat_cv {
PSRWLOCK srl;
};
+#define NNI_CV_INITIALIZER(mxp) { .srl = mxp, .cv = CONDITION_VARIABLE_INIT }
+
struct nni_atomic_flag {
unsigned f;
};
diff --git a/src/platform/windows/win_resolv.c b/src/platform/windows/win_resolv.c
index 8628719f..f855e255 100644
--- a/src/platform/windows/win_resolv.c
+++ b/src/platform/windows/win_resolv.c
@@ -1,5 +1,5 @@
//
-// Copyright 2020 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2021 Staysail Systems, Inc. <info@staysail.tech>
// Copyright 2018 Capitar IT Group BV <info@capitar.com>
//
// This software is supplied under the terms of the MIT License, a
@@ -26,9 +26,9 @@
#define NNG_RESOLV_CONCURRENCY 4
#endif
-static nni_mtx resolv_mtx;
-static nni_cv resolv_cv;
-static bool resolv_fini;
+static nni_mtx resolv_mtx = NNI_MTX_INITIALIZER;
+static nni_cv resolv_cv = NNI_CV_INITIALIZER(&resolv_mtx);
+static bool resolv_fini = false;
static nni_list resolv_aios;
static nni_thr resolv_thrs[NNG_RESOLV_CONCURRENCY];
@@ -408,11 +408,9 @@ nni_parse_ip_port(const char *addr, nni_sockaddr *sa)
int
nni_win_resolv_sysinit(void)
{
- nni_mtx_init(&resolv_mtx);
- nni_cv_init(&resolv_cv, &resolv_mtx);
nni_aio_list_init(&resolv_aios);
-
resolv_fini = false;
+
for (int i = 0; i < NNG_RESOLV_CONCURRENCY; i++) {
int rv = nni_thr_init(&resolv_thrs[i], resolv_worker, NULL);
if (rv != 0) {
@@ -437,8 +435,6 @@ nni_win_resolv_sysfini(void)
for (int i = 0; i < NNG_RESOLV_CONCURRENCY; i++) {
nni_thr_fini(&resolv_thrs[i]);
}
- nni_cv_fini(&resolv_cv);
- nni_mtx_fini(&resolv_mtx);
}
#endif // NNG_PLATFORM_WINDOWS