1 /* 2 * Copyright (c) 2025 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_TASK_GROUP_MANAGER_H 17 #define JS_CONCURRENT_MODULE_TASKPOOL_TASK_GROUP_MANAGER_H 18 19 #include "task_group.h" 20 21 namespace Commonlibrary::Concurrent::TaskPoolModule { 22 class TaskGroupManager { 23 public: 24 static TaskGroupManager& GetInstance(); 25 26 void AddTask(uint64_t groupId, napi_ref taskRef, uint32_t taskId); 27 void StoreTaskGroup(uint64_t groupId, TaskGroup* taskGroup); 28 void RemoveTaskGroup(uint64_t groupId); 29 TaskGroup* GetTaskGroup(uint64_t groupId); 30 void CancelGroup(napi_env env, uint64_t groupId); 31 void CancelGroupTask(napi_env env, uint32_t taskId, TaskGroup* group); 32 void ReleaseTaskGroupData(napi_env env, TaskGroup* group); 33 bool UpdateGroupState(uint64_t groupId); 34 35 private: 36 TaskGroupManager() = default; 37 ~TaskGroupManager() = default; 38 TaskGroupManager(const TaskGroupManager &) = delete; 39 TaskGroupManager& operator=(const TaskGroupManager &) = delete; 40 TaskGroupManager(TaskGroupManager &&) = delete; 41 TaskGroupManager& operator=(TaskGroupManager &&) = delete; 42 43 // <groupId, TaskGroup> 44 std::unordered_map<uint64_t, TaskGroup*> taskGroups_ {}; 45 std::mutex taskGroupsMutex_; 46 friend class NativeEngineTest; 47 }; 48 } // namespace Commonlibrary::Concurrent::TaskPoolModule 49 #endif // JS_CONCURRENT_MODULE_TASKPOOL_TASK_GROUP_MANAGER_H