1 /* 2 * Copyright (C) 2023 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 OHOS_SAMGR_FFRT_HANDLER_H 17 #define OHOS_SAMGR_FFRT_HANDLER_H 18 19 #include <map> 20 #include <shared_mutex> 21 #include <string> 22 23 #include "ffrt.h" 24 25 namespace OHOS { 26 class FFRTHandler { 27 public: 28 explicit FFRTHandler(const std::string& name); 29 ~FFRTHandler() = default; 30 bool PostTask(std::function<void()> func); 31 bool PostTask(std::function<void()> func, uint64_t delayTime); 32 bool PostTask(std::function<void()> func, const std::string& name, uint64_t delayTime); 33 void RemoveTask(const std::string& name); 34 void DelTask(const std::string& name); 35 bool HasInnerEvent(const std::string name); 36 void CleanFfrt(); 37 void SetFfrt(const std::string& name); 38 39 private: 40 std::shared_mutex mutex_; 41 std::map<std::string, ffrt::task_handle> taskMap_; 42 std::shared_ptr<ffrt::queue> queue_; 43 }; 44 } // namespace OHOS 45 #endif // OHOS_SAMGR_FFRT_HANDLER_H