aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2025-01-05 09:21:33 -0800
committerGarrett D'Amore <garrett@damore.org>2025-01-05 09:48:37 -0800
commitcf7dda752e1a49cb1003b0e300a5200ff0b0c92e (patch)
tree070797fdfbe72a754dbfe6a0f688ce9ab3ac4af8
parenta300db42527a3eff0b037b3aa5fa3ff50f8227d4 (diff)
downloadnng-cf7dda752e1a49cb1003b0e300a5200ff0b0c92e.tar.gz
nng-cf7dda752e1a49cb1003b0e300a5200ff0b0c92e.tar.bz2
nng-cf7dda752e1a49cb1003b0e300a5200ff0b0c92e.zip
platform: eliminate NNI_CV_INITIALIZER altogether
-rw-r--r--src/platform/posix/posix_impl.h8
-rw-r--r--src/platform/posix/posix_resolv_gai.c16
-rw-r--r--src/platform/windows/win_impl.h5
-rw-r--r--src/platform/windows/win_resolv.c14
4 files changed, 19 insertions, 24 deletions
diff --git a/src/platform/posix/posix_impl.h b/src/platform/posix/posix_impl.h
index 4cac6beb..b6435353 100644
--- a/src/platform/posix/posix_impl.h
+++ b/src/platform/posix/posix_impl.h
@@ -81,14 +81,6 @@ struct nni_plat_cv {
pthread_mutex_t *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)->mtx), .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 9090107b..c5051ffd 100644
--- a/src/platform/posix/posix_resolv_gai.c
+++ b/src/platform/posix/posix_resolv_gai.c
@@ -1,5 +1,5 @@
//
-// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2025 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
@@ -8,9 +8,9 @@
// found online at https://opensource.org/licenses/MIT.
//
+#include "core/defs.h"
#include "core/init.h"
#include "core/nng_impl.h"
-#include "nng/nng.h"
#ifdef NNG_USE_POSIX_RESOLV_GAI
@@ -45,13 +45,13 @@
#endif
#endif
-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;
static nni_aio **resolv_active;
static int16_t resolv_num_thr;
+static nni_mtx resolv_mtx;
+static nni_cv resolv_cv;
static void
resolv_cancel(nni_aio *aio, void *arg, int rv)
@@ -434,13 +434,17 @@ nni_posix_resolv_sysfini(void)
NNI_FREE_STRUCTS(resolv_thrs, resolv_num_thr);
}
if (resolv_active != NULL) {
- NNI_FREE_STRUCTS(resolv_active, resolv_num_thr);
+ nni_free(resolv_active, sizeof(nni_aio *) * resolv_num_thr);
}
+ nni_cv_fini(&resolv_cv);
+ nni_mtx_fini(&resolv_mtx);
}
int
nni_posix_resolv_sysinit(nng_init_params *params)
{
+ nni_mtx_init(&resolv_mtx);
+ nni_cv_init(&resolv_cv, &resolv_mtx);
resolv_fini = false;
nni_aio_list_init(&resolv_aios);
@@ -451,7 +455,7 @@ nni_posix_resolv_sysinit(nng_init_params *params)
params->num_resolver_threads = resolv_num_thr;
// no limit on the maximum for now
resolv_thrs = NNI_ALLOC_STRUCTS(resolv_thrs, resolv_num_thr);
- resolv_active = NNI_ALLOC_STRUCTS(resolv_active, resolv_num_thr);
+ resolv_active = nni_zalloc(sizeof(nni_aio *) * resolv_num_thr);
if (resolv_thrs == NULL || resolv_active == NULL) {
nni_posix_resolv_sysfini();
return (NNG_ENOMEM);
diff --git a/src/platform/windows/win_impl.h b/src/platform/windows/win_impl.h
index fd02e080..1659b099 100644
--- a/src/platform/windows/win_impl.h
+++ b/src/platform/windows/win_impl.h
@@ -59,11 +59,6 @@ struct nni_plat_cv {
PSRWLOCK srl;
};
-#define NNI_CV_INITIALIZER(mxp) \
- { \
- .srl = (void *) mxp, .cv = CONDITION_VARIABLE_INIT \
- }
-
struct nni_atomic_flag {
LONG f;
};
diff --git a/src/platform/windows/win_resolv.c b/src/platform/windows/win_resolv.c
index 6701136e..50b030da 100644
--- a/src/platform/windows/win_resolv.c
+++ b/src/platform/windows/win_resolv.c
@@ -1,5 +1,5 @@
//
-// Copyright 2024 Staysail Systems, Inc. <info@staysail.tech>
+// Copyright 2025 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
@@ -22,13 +22,13 @@
// host file, WINS, or other naming services. As a result, we just build
// our own limited asynchronous resolver with threads.
-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;
static nni_aio **resolv_active;
static int16_t resolv_num_thr;
+static nni_mtx resolv_mtx;
+static nni_cv resolv_cv;
static void
resolv_cancel(nni_aio *aio, void *arg, int rv)
@@ -383,6 +383,8 @@ nni_get_port_by_name(const char *name, uint32_t *portp)
int
nni_win_resolv_sysinit(nng_init_params *params)
{
+ nni_mtx_init(&resolv_mtx);
+ nni_cv_init(&resolv_cv, &resolv_mtx);
nni_aio_list_init(&resolv_aios);
resolv_fini = false;
@@ -394,7 +396,7 @@ nni_win_resolv_sysinit(nng_init_params *params)
// no limit on the maximum for now
resolv_thrs = NNI_ALLOC_STRUCTS(resolv_thrs, resolv_num_thr);
- resolv_active = NNI_ALLOC_STRUCTS(resolv_active, resolv_num_thr);
+ resolv_active = nni_zalloc(sizeof(nni_aio *) * resolv_num_thr);
if (resolv_thrs == NULL || resolv_active == NULL) {
nni_win_resolv_sysfini();
return (NNG_ENOMEM);
@@ -428,8 +430,10 @@ nni_win_resolv_sysfini(void)
NNI_FREE_STRUCTS(resolv_thrs, resolv_num_thr);
}
if (resolv_active != NULL) {
- NNI_FREE_STRUCTS(resolv_active, resolv_num_thr);
+ nni_free(resolv_active, sizeof(nni_aio *) * resolv_num_thr);
}
+ nni_cv_fini(&resolv_cv);
+ nni_mtx_fini(&resolv_mtx);
}
#endif // NNG_PLATFORM_WINDOWS