/* * Copyright (c) 2024-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef HISTREAMER_FOUNDATION_OSAL_PIPELINETHREADPOOL_H #define HISTREAMER_FOUNDATION_OSAL_PIPELINETHREADPOOL_H #include #include #include #include #include #include "osal/task/condition_variable.h" #include "osal/task/mutex.h" #include "osal/task/autolock.h" #include "osal/task/thread.h" namespace OHOS { namespace Media { class TaskInner; class PipeLineThread { public: PipeLineThread(std::string groupId, TaskType type, TaskPriority priority); ~PipeLineThread(); void Run(); void AddTask(std::shared_ptr task); void RemoveTask(std::shared_ptr task); void LockJobState(); void UnLockJobState(bool notifyChange); void Exit(); bool IsRunningInSelf(); std::string groupId_; std::string name_; TaskType type_; private: std::list> taskList_; std::unique_ptr loop_; FairMutex mutex_; ConditionVariable syncCond_; std::atomic threadExit_; }; class PipeLineThreadPool { public: static PipeLineThreadPool &GetInstance(); std::shared_ptr FindThread(const std::string &groupId, TaskType taskType, TaskPriority priority); void DestroyThread(const std::string &groupId); private: PipeLineThreadPool() = default; ~PipeLineThreadPool() = default; std::map>>> workerGroupMap; Mutex mutex_; }; } // namespace Media } // namespace OHOS #endif // HISTREAMER_FOUNDATION_OSAL_PIPELINETHREADPOOL_H