aboutsummaryrefslogtreecommitdiff
path: root/src/platform
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2016-12-14 18:53:10 -0800
committerGarrett D'Amore <garrett@damore.org>2016-12-14 18:53:10 -0800
commit3583d5e407476b8836228c0abc52c400d74aba61 (patch)
tree113b6510b9f3d4f7eaffd331ecbd173724327c96 /src/platform
parente6476c5e4eac773aed4b76f16d3e76e7956c2468 (diff)
downloadnng-3583d5e407476b8836228c0abc52c400d74aba61.tar.gz
nng-3583d5e407476b8836228c0abc52c400d74aba61.tar.bz2
nng-3583d5e407476b8836228c0abc52c400d74aba61.zip
More robust platform definition support.
The idea is that someday it will be possible to just concatenate the entire set of source files into a single giant source file, for systems that want to work this way. As a result, the build system now compiles every file, although some of them will not have any definitions.
Diffstat (limited to 'src/platform')
-rw-r--r--src/platform/posix/posix_alloc.c (renamed from src/platform/posix/posix_alloc.h)8
-rw-r--r--src/platform/posix/posix_clock.c (renamed from src/platform/posix/posix_clock.h)5
-rw-r--r--src/platform/posix/posix_debug.c (renamed from src/platform/posix/posix_debug.h)22
-rw-r--r--src/platform/posix/posix_impl.h13
-rw-r--r--src/platform/posix/posix_synch.c (renamed from src/platform/posix/posix_synch.h)6
-rw-r--r--src/platform/posix/posix_thread.c (renamed from src/platform/posix/posix_thread.h)21
-rw-r--r--src/platform/posix/posix_vsnprintf.c (renamed from src/platform/posix/posix_vsnprintf.h)8
7 files changed, 56 insertions, 27 deletions
diff --git a/src/platform/posix/posix_alloc.h b/src/platform/posix/posix_alloc.c
index 8451cc9c..b47a95b2 100644
--- a/src/platform/posix/posix_alloc.h
+++ b/src/platform/posix/posix_alloc.c
@@ -27,6 +27,12 @@
* get multiple symbols defined.
*/
+#include "core/nng_impl.h"
+
+#ifdef PLATFORM_POSIX_ALLOC
+
+#include <stdlib.h>
+
/*
* POSIX memory allocation. This is pretty much standard C.
*/
@@ -43,3 +49,5 @@ nni_free(void *ptr, size_t size)
NNI_ARG_UNUSED(size);
free(ptr);
}
+
+#endif \ No newline at end of file
diff --git a/src/platform/posix/posix_clock.h b/src/platform/posix/posix_clock.c
index 07fc603d..c772263c 100644
--- a/src/platform/posix/posix_clock.h
+++ b/src/platform/posix/posix_clock.c
@@ -30,6 +30,9 @@
/*
* POSIX clock stuff.
*/
+#include "core/nng_impl.h"
+
+#ifdef PLATFORM_POSIX_CLOCK
#include <time.h>
#include <errno.h>
@@ -147,3 +150,5 @@ nni_usleep(uint64_t usec)
}
#endif /* NNG_USE_GETTIMEOFDAY */
+
+#endif /* PLATFORM_POSIX_CLOCK */
diff --git a/src/platform/posix/posix_debug.h b/src/platform/posix/posix_debug.c
index d25a6c11..6b2d875a 100644
--- a/src/platform/posix/posix_debug.h
+++ b/src/platform/posix/posix_debug.c
@@ -20,29 +20,23 @@
* IN THE SOFTWARE.
*/
+#include "core/nng_impl.h"
+
+#ifdef PLATFORM_POSIX_DEBUG
+
#include <stdlib.h>
#include <stdio.h>
-void (*debug_out)(const char *line);
-
void
-nni_abort(void)
+nni_plat_abort(void)
{
abort();
}
void
-nni_debug_out(const char *message)
+nni_plat_println(const char *message)
{
- if (debug_out != NULL) {
- debug_out(message);
- } else {
- (void) fprintf(stderr, "%s\n", message);
- }
+ (void) fprintf(stderr, "%s\n", message);
}
-void
-nni_set_debug_out(void (*out)(const char *))
-{
- debug_out = out;
-}
+#endif /* PLATFORM_POSIX_DEBUG */ \ No newline at end of file
diff --git a/src/platform/posix/posix_impl.h b/src/platform/posix/posix_impl.h
index 60a1d663..48b6e99b 100644
--- a/src/platform/posix/posix_impl.h
+++ b/src/platform/posix/posix_impl.h
@@ -31,11 +31,12 @@
*/
#ifdef PLATFORM_POSIX
+#define PLATFORM_POSIX_ALLOC
+#define PLATFORM_POSIX_DEBUG
+#define PLATFORM_POSIX_CLOCK
+#define PLATFORM_POSIX_SYNCH
+#define PLATFORM_POSIX_THREAD
+#define PLATFORM_POSIX_VSNPRINTF
+
#include "platform/posix/posix_config.h"
-#include "platform/posix/posix_debug.h"
-#include "platform/posix/posix_alloc.h"
-#include "platform/posix/posix_clock.h"
-#include "platform/posix/posix_synch.h"
-#include "platform/posix/posix_thread.h"
-#include "platform/posix/posix_vsnprintf.h"
#endif
diff --git a/src/platform/posix/posix_synch.h b/src/platform/posix/posix_synch.c
index d3e44411..cb8b30dd 100644
--- a/src/platform/posix/posix_synch.h
+++ b/src/platform/posix/posix_synch.c
@@ -32,6 +32,10 @@
* pthreads.
*/
+#include "core/nng_impl.h"
+
+#ifdef PLATFORM_POSIX_SYNCH
+
#include <pthread.h>
#include <time.h>
@@ -235,3 +239,5 @@ nni_cond_timedwait(nni_cond_t c, uint64_t usec)
}
return (0);
}
+
+#endif \ No newline at end of file
diff --git a/src/platform/posix/posix_thread.h b/src/platform/posix/posix_thread.c
index 27ad888f..a41c7e7c 100644
--- a/src/platform/posix/posix_thread.h
+++ b/src/platform/posix/posix_thread.c
@@ -31,6 +31,10 @@
* POSIX threads.
*/
+#include "core/nng_impl.h"
+
+#ifdef PLATFORM_POSIX_THREAD
+
#include <pthread.h>
#include <time.h>
#include <string.h>
@@ -66,7 +70,7 @@ nni_thread_create(nni_thread_t *tp, void (*fn)(void *), void *arg)
thr->func = fn;
thr->arg = arg;
- if ((rv = pthread_create(&thr->tid, thr, thrfunc, arg)) != 0) {
+ if ((rv = pthread_create(&thr->tid, NULL, thrfunc, thr)) != 0) {
nni_free(thr, sizeof (*thr));
return (NNG_ENOMEM);
}
@@ -91,8 +95,9 @@ atfork_child(void)
}
int
-nni_platform_init(void)
+nni_plat_init(int (*helper)(void))
{
+ int rv;
if (plat_fork) {
nni_panic("nng is fork-reentrant safe");
}
@@ -108,14 +113,18 @@ nni_platform_init(void)
pthread_mutex_unlock(&plat_lock);
return (NNG_ENOMEM);
}
- plat_init = 1;
+ if ((rv = helper()) == 0) {
+ plat_init = 1;
+ }
pthread_mutex_unlock(&plat_lock);
- return (0);
+ return (rv);
}
void
-nni_platform_fini(void)
+nni_plat_fini(void)
{
/* XXX: NOTHING *YET* */
-} \ No newline at end of file
+}
+
+#endif \ No newline at end of file
diff --git a/src/platform/posix/posix_vsnprintf.h b/src/platform/posix/posix_vsnprintf.c
index 8270d255..42367b4c 100644
--- a/src/platform/posix/posix_vsnprintf.h
+++ b/src/platform/posix/posix_vsnprintf.c
@@ -20,11 +20,17 @@
* IN THE SOFTWARE.
*/
+#include "core/nng_impl.h"
+
+#ifdef PLATFORM_POSIX_VSNPRINTF
+
#include <stdarg.h>
#include <stdio.h>
void
-nni_vsnprintf(char *dst, size_t sz, const char *fmt, va_list va)
+nni_plat_vsnprintf(char *dst, size_t sz, const char *fmt, va_list va)
{
(void) vsnprintf(dst, sz, fmt, va);
}
+
+#endif \ No newline at end of file