aboutsummaryrefslogtreecommitdiff
path: root/src/platform
diff options
context:
space:
mode:
authorGarrett D'Amore <garrett@damore.org>2018-06-12 00:40:37 -0700
committerGarrett D'Amore <garrett@damore.org>2018-06-12 00:40:37 -0700
commite60308808f58a3517170edf61245031cb899e59e (patch)
tree79c78ac8fbde2efef1c179e5c2cc6c23fff1f64d /src/platform
parent061beeabd9859f92917ae3f0c5657dd8eca44d68 (diff)
downloadnng-e60308808f58a3517170edf61245031cb899e59e.tar.gz
nng-e60308808f58a3517170edf61245031cb899e59e.tar.bz2
nng-e60308808f58a3517170edf61245031cb899e59e.zip
fixes #32 autoscale based on CPUs available
This should work on both Windows and the most common POSIX variants. We will create at least two threads for running completions, but there are numerous other threads in the code.
Diffstat (limited to 'src/platform')
-rw-r--r--src/platform/posix/posix_thread.c12
-rw-r--r--src/platform/windows/win_thread.c9
2 files changed, 21 insertions, 0 deletions
diff --git a/src/platform/posix/posix_thread.c b/src/platform/posix/posix_thread.c
index f016ca3f..df2ee9d2 100644
--- a/src/platform/posix/posix_thread.c
+++ b/src/platform/posix/posix_thread.c
@@ -336,4 +336,16 @@ nni_plat_fini(void)
pthread_mutex_unlock(&nni_plat_init_lock);
}
+int
+nni_plat_ncpu(void)
+{
+ // POSIX specifies sysconf exists, but not the value
+ // _SC_NPROCESSORS_ONLN. Nonetheless, everybody implements it.
+ // If you don't we'll assume you only have a single logical CPU.
+#ifdef _SC_NPROCESSORS_ONLN
+ return (sysconf(_SC_NPROCESSORS_ONLN));
+#else
+ return (1);
+#endif
+}
#endif // NNG_PLATFORM_POSIX
diff --git a/src/platform/windows/win_thread.c b/src/platform/windows/win_thread.c
index 2e9d58d7..a3d932aa 100644
--- a/src/platform/windows/win_thread.c
+++ b/src/platform/windows/win_thread.c
@@ -148,6 +148,15 @@ nni_plat_thr_is_self(nni_plat_thr *thr)
static LONG plat_inited = 0;
int
+nni_plat_ncpu(void)
+{
+ SYSTEM_INFO info;
+
+ GetSystemInfo(&info);
+ return ((int) (info.dwNumberOfProcessors));
+}
+
+int
nni_plat_init(int (*helper)(void))
{
int rv = 0;