1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef JS_CONCURRENT_MODULE_TASKPOOL_TASKPOOL_H_ 17 #define JS_CONCURRENT_MODULE_TASKPOOL_TASKPOOL_H_ 18 19 #include <mutex> 20 21 #include "napi/native_api.h" 22 #include "napi/native_node_api.h" 23 #include "native_engine/native_engine.h" 24 #include "task.h" 25 26 namespace Commonlibrary::Concurrent::TaskPoolModule { 27 enum Priority { 28 HIGH, 29 MEDIUM, 30 LOW 31 }; 32 33 class TaskPool { 34 public: 35 static napi_value InitTaskPool(napi_env env, napi_value exports); 36 37 private: 38 TaskPool() = delete; 39 ~TaskPool() = delete; 40 TaskPool(const TaskPool &) = delete; 41 TaskPool& operator=(const TaskPool &) = delete; 42 TaskPool(TaskPool &&) = delete; 43 TaskPool& operator=(TaskPool &&) = delete; 44 45 static napi_value Execute(napi_env env, napi_callback_info cbinfo); 46 static napi_value Cancel(napi_env env, napi_callback_info cbinfo); 47 48 static napi_value ExecuteFunction(napi_env env, napi_value object); 49 static napi_value ExecuteTask(napi_env env, Task* task); 50 static void HandleTaskResult(const uv_async_t* req); 51 52 friend class TaskManager; 53 }; 54 } // namespace Commonlibrary::Concurrent::TaskPoolModule 55 #endif // JS_CONCURRENT_MODULE_TASKPOOL_TASKPOOL_H_