Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2018-08-19 07:34:17 +0300
committercjihrig <cjihrig@gmail.com>2018-08-23 00:27:16 +0300
commit92880f31da1eca98a42e0f61708b10d9d8d83955 (patch)
tree757a193b936f0a127b3445985ff688dd75ddab48 /src/node_os.cc
parent91eec00ca20a54b1dc010cfc2fb34bc2f39eab6b (diff)
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 'src/node_os.cc')
-rw-r--r--src/node_os.cc43
1 files changed, 43 insertions, 0 deletions
diff --git a/src/node_os.cc b/src/node_os.cc
index c9eef808b0a..d3e9460f473 100644
--- a/src/node_os.cc
+++ b/src/node_os.cc
@@ -52,6 +52,7 @@ using v8::Context;
using v8::Float64Array;
using v8::Function;
using v8::FunctionCallbackInfo;
+using v8::Int32;
using v8::Integer;
using v8::Local;
using v8::MaybeLocal;
@@ -405,6 +406,46 @@ static void GetUserInfo(const FunctionCallbackInfo<Value>& args) {
}
+static void SetPriority(const FunctionCallbackInfo<Value>& args) {
+ Environment* env = Environment::GetCurrent(args);
+
+ CHECK_EQ(args.Length(), 3);
+ CHECK(args[0]->IsInt32());
+ CHECK(args[1]->IsInt32());
+
+ const int pid = args[0].As<Int32>()->Value();
+ const int priority = args[1].As<Int32>()->Value();
+ const int err = uv_os_setpriority(pid, priority);
+
+ if (err) {
+ CHECK(args[2]->IsObject());
+ env->CollectUVExceptionInfo(args[2], err, "uv_os_setpriority");
+ }
+
+ args.GetReturnValue().Set(err);
+}
+
+
+static void GetPriority(const FunctionCallbackInfo<Value>& args) {
+ Environment* env = Environment::GetCurrent(args);
+
+ CHECK_EQ(args.Length(), 2);
+ CHECK(args[0]->IsInt32());
+
+ const int pid = args[0].As<Int32>()->Value();
+ int priority;
+ const int err = uv_os_getpriority(pid, &priority);
+
+ if (err) {
+ CHECK(args[1]->IsObject());
+ env->CollectUVExceptionInfo(args[1], err, "uv_os_getpriority");
+ return;
+ }
+
+ args.GetReturnValue().Set(priority);
+}
+
+
void Initialize(Local<Object> target,
Local<Value> unused,
Local<Context> context) {
@@ -420,6 +461,8 @@ void Initialize(Local<Object> target,
env->SetMethod(target, "getInterfaceAddresses", GetInterfaceAddresses);
env->SetMethod(target, "getHomeDirectory", GetHomeDirectory);
env->SetMethod(target, "getUserInfo", GetUserInfo);
+ env->SetMethod(target, "setPriority", SetPriority);
+ env->SetMethod(target, "getPriority", GetPriority);
target->Set(FIXED_ONE_BYTE_STRING(env->isolate(), "isBigEndian"),
Boolean::New(env->isolate(), IsBigEndian()));
}