summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2018-08-19 00:34:17 -0400
committercjihrig <cjihrig@gmail.com>2018-08-22 17:27:16 -0400
commit92880f31da1eca98a42e0f61708b10d9d8d83955 (patch)
tree757a193b936f0a127b3445985ff688dd75ddab48 /lib
parent91eec00ca20a54b1dc010cfc2fb34bc2f39eab6b (diff)
downloadandroid-node-v8-92880f31da1eca98a42e0f61708b10d9d8d83955.tar.gz
android-node-v8-92880f31da1eca98a42e0f61708b10d9d8d83955.tar.bz2
android-node-v8-92880f31da1eca98a42e0f61708b10d9d8d83955.zip
os: add os.{get,set}Priority()
PR-URL: https://github.com/nodejs/node/pull/22407 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/constants.js1
-rw-r--r--lib/os.js37
2 files changed, 37 insertions, 1 deletions
diff --git a/lib/constants.js b/lib/constants.js
index dee4612644..a4c2ca6fb3 100644
--- a/lib/constants.js
+++ b/lib/constants.js
@@ -29,6 +29,7 @@ const constants = process.binding('constants');
Object.assign(exports,
constants.os.dlopen,
constants.os.errno,
+ constants.os.priority,
constants.os.signals,
constants.fs,
constants.crypto);
diff --git a/lib/os.js b/lib/os.js
index 15d06f1576..09a70d2f7b 100644
--- a/lib/os.js
+++ b/lib/os.js
@@ -27,6 +27,7 @@ const { deprecate } = require('internal/util');
const isWindows = process.platform === 'win32';
const { codes: { ERR_SYSTEM_ERROR } } = require('internal/errors');
+const { validateInt32 } = require('internal/validators');
const {
getCPUs,
@@ -37,10 +38,12 @@ const {
getLoadAvg,
getOSRelease: _getOSRelease,
getOSType: _getOSType,
+ getPriority: _getPriority,
getTotalMem,
getUserInfo: _getUserInfo,
getUptime,
- isBigEndian
+ isBigEndian,
+ setPriority: _setPriority
} = process.binding('os');
function getCheckedFunction(fn) {
@@ -206,17 +209,49 @@ function networkInterfaces() {
return interfaceAddresses;
}
+function setPriority(pid, priority) {
+ if (priority === undefined) {
+ priority = pid;
+ pid = 0;
+ }
+
+ validateInt32(pid, 'pid');
+ validateInt32(priority, 'priority', -20, 19);
+
+ const ctx = {};
+
+ if (_setPriority(pid, priority, ctx) !== 0)
+ throw new ERR_SYSTEM_ERROR(ctx);
+}
+
+function getPriority(pid) {
+ if (pid === undefined)
+ pid = 0;
+ else
+ validateInt32(pid, 'pid');
+
+ const ctx = {};
+ const priority = _getPriority(pid, ctx);
+
+ if (priority === undefined)
+ throw new ERR_SYSTEM_ERROR(ctx);
+
+ return priority;
+}
+
module.exports = {
arch,
cpus,
endianness,
freemem: getFreeMem,
+ getPriority,
homedir: getHomeDirectory,
hostname: getHostname,
loadavg,
networkInterfaces,
platform,
release: getOSRelease,
+ setPriority,
tmpdir,
totalmem: getTotalMem,
type: getOSType,