aboutsummaryrefslogtreecommitdiff
path: root/src/platform/posix
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2021-12-05 22:11:24 -0500
committerGarrett D'Amore <garrett@damore.org>2021-12-05 23:04:45 -0500
commitc9bbe8eb574fe10ff16cc71a23fcc9b31fb8ed04 (patch)
tree3a135bbee8750cc1b1869cfca6a2e6f24bf8e59c /src/platform/posix
parenteee06d1e8365ea1b1aa9363a3c6445745b002324 (diff)
downloadnng-c9bbe8eb574fe10ff16cc71a23fcc9b31fb8ed04.tar.gz
nng-c9bbe8eb574fe10ff16cc71a23fcc9b31fb8ed04.tar.bz2
nng-c9bbe8eb574fe10ff16cc71a23fcc9b31fb8ed04.zip
Use static initialization for lists and mutexes.
This eliminates some run-time initialization, moving it to compile time. Additional follow up work will expand on this to simplify initialization and reduce the need for certain locks.
Diffstat (limited to 'src/platform/posix')
-rw-r--r--src/platform/posix/posix_impl.h6
-rw-r--r--src/platform/posix/posix_thread.c2
2 files changed, 7 insertions, 1 deletions
diff --git a/src/platform/posix/posix_impl.h b/src/platform/posix/posix_impl.h
index 234d1501..97924a45 100644
--- a/src/platform/posix/posix_impl.h
+++ b/src/platform/posix/posix_impl.h
@@ -58,10 +58,16 @@ struct nni_plat_mtx {
pthread_mutex_t mtx;
};
+#define NNI_MTX_INITIALIZER { 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 {
pthread_cond_t cv;
nni_plat_mtx *mtx;
diff --git a/src/platform/posix/posix_thread.c b/src/platform/posix/posix_thread.c
index c47bcec6..b7cd5e1e 100644
--- a/src/platform/posix/posix_thread.c
+++ b/src/platform/posix/posix_thread.c
@@ -34,7 +34,7 @@
#endif
static pthread_mutex_t nni_plat_init_lock = PTHREAD_MUTEX_INITIALIZER;
-static int nni_plat_inited = 0;
+static volatile int nni_plat_inited = 0;
static int nni_plat_forked = 0;
pthread_condattr_t nni_cvattr;