146debc2cSopenharmony_ci/* 246debc2cSopenharmony_ci * Copyright (c) 2024 Huawei Device Co., Ltd. 346debc2cSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 446debc2cSopenharmony_ci * you may not use this file except in compliance with the License. 546debc2cSopenharmony_ci * You may obtain a copy of the License at 646debc2cSopenharmony_ci * 746debc2cSopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 846debc2cSopenharmony_ci * 946debc2cSopenharmony_ci * Unless required by applicable law or agreed to in writing, software 1046debc2cSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 1146debc2cSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 1246debc2cSopenharmony_ci * See the License for the specific language governing permissions and 1346debc2cSopenharmony_ci * limitations under the License. 1446debc2cSopenharmony_ci */ 1546debc2cSopenharmony_ci 1646debc2cSopenharmony_ci#ifndef OPERATION_QUEUE_H 1746debc2cSopenharmony_ci#define OPERATION_QUEUE_H 1846debc2cSopenharmony_ci 1946debc2cSopenharmony_ci#include <list> 2046debc2cSopenharmony_ci#include <thread> 2146debc2cSopenharmony_ci#include <atomic> 2246debc2cSopenharmony_ci#include "thread_sync_wait.h" 2346debc2cSopenharmony_ci 2446debc2cSopenharmony_cinamespace OHOS { 2546debc2cSopenharmony_cinamespace Print { 2646debc2cSopenharmony_ciclass OperationQueue { 2746debc2cSopenharmony_cipublic: 2846debc2cSopenharmony_ci void Run(); 2946debc2cSopenharmony_ci void Stop(); 3046debc2cSopenharmony_ci bool Push(std::function<void()> op); 3146debc2cSopenharmony_ci 3246debc2cSopenharmony_ciprivate: 3346debc2cSopenharmony_ci std::function<void()> Pop(); 3446debc2cSopenharmony_ci 3546debc2cSopenharmony_ciprivate: 3646debc2cSopenharmony_ci std::thread opThread; 3746debc2cSopenharmony_ci std::list<std::function<void()>> opList; 3846debc2cSopenharmony_ci std::mutex listMutex; 3946debc2cSopenharmony_ci std::atomic<bool> isRunning{ false }; 4046debc2cSopenharmony_ci size_t maxCount = 100; 4146debc2cSopenharmony_ci ThreadSyncWait syncWait; 4246debc2cSopenharmony_ci}; 4346debc2cSopenharmony_ci} // namespace Print 4446debc2cSopenharmony_ci} // namespace OHOS 4546debc2cSopenharmony_ci#endif // OPERATION_QUEUE_H 46