summaryrefslogtreecommitdiff
path: root/src/util.cc
diff options
context:
space:
mode:
authorBen Noordhuis <info@bnoordhuis.nl>2017-11-20 23:37:50 +0100
committerBen Noordhuis <info@bnoordhuis.nl>2017-11-20 23:37:50 +0100
commit7dc35e937d6b3cf57e6184dfc3d54633e5b69082 (patch)
tree486c58a6c57a33611ee526fb1acfd63e2991d5fa /src/util.cc
parent65439b4c17e14890a67f3db832fde6cfd15ac59c (diff)
downloadandroid-node-v8-7dc35e937d6b3cf57e6184dfc3d54633e5b69082.tar.gz
android-node-v8-7dc35e937d6b3cf57e6184dfc3d54633e5b69082.tar.bz2
android-node-v8-7dc35e937d6b3cf57e6184dfc3d54633e5b69082.zip
src: abstract getpid() operation
There are a few places where we paper over the fact that getpid() is called GetCurrentProcessId() on Windows. Let's move it into a function. PR-URL: https://github.com/nodejs/node/pull/17087 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Eugene Ostroukhov <eostroukhov@google.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
Diffstat (limited to 'src/util.cc')
-rw-r--r--src/util.cc16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/util.cc b/src/util.cc
index ef93d16968..0fb897bc8e 100644
--- a/src/util.cc
+++ b/src/util.cc
@@ -24,6 +24,14 @@
#include "node_internals.h"
#include <stdio.h>
+#ifdef __POSIX__
+#include <unistd.h> // getpid()
+#endif
+
+#ifdef _MSC_VER
+#include <windows.h> // GetCurrentProcessId()
+#endif
+
namespace node {
using v8::Isolate;
@@ -105,4 +113,12 @@ void LowMemoryNotification() {
}
}
+uint32_t GetProcessId() {
+#ifdef _WIN32
+ return GetCurrentProcessId();
+#else
+ return getpid();
+#endif
+}
+
} // namespace node