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 #include "progress_queue.h" 16 17 namespace OHOS::UDMF { 18 PushBack(ProgressInfo & progress)19void ProgressQueue::PushBack(ProgressInfo &progress) 20 { 21 std::lock_guard<std::mutex> lock(mutex_); 22 queue_.push(progress); 23 } 24 Poll()25std::pair<bool, std::shared_ptr<ProgressInfo>> ProgressQueue::Poll() 26 { 27 std::lock_guard<std::mutex> lock(mutex_); 28 if (queue_.empty()) { 29 return {false, nullptr}; 30 } 31 auto progressInfo = std::make_shared<ProgressInfo>(queue_.front()); 32 queue_.pop(); 33 return {true, progressInfo}; 34 } 35 IsCancel() const36bool ProgressQueue::IsCancel() const 37 { 38 std::lock_guard<std::mutex> lock(mutex_); 39 return cancelFlag_; 40 } 41 Cancel()42void ProgressQueue::Cancel() 43 { 44 std::lock_guard<std::mutex> lock(mutex_); 45 cancelFlag_ = true; 46 } 47 SetClearable(const bool clearableFlag)48void ProgressQueue::SetClearable(const bool clearableFlag) 49 { 50 std::lock_guard<std::mutex> lock(mutex_); 51 clearableFlag_ = clearableFlag; 52 } 53 Clear()54bool ProgressQueue::Clear() 55 { 56 std::lock_guard<std::mutex> lock(mutex_); 57 auto oldClearableFlag = clearableFlag_; 58 clearableFlag_ = true; 59 return oldClearableFlag; 60 } 61 IsClear() const62bool ProgressQueue::IsClear() const 63 { 64 std::lock_guard<std::mutex> lock(mutex_); 65 return clearableFlag_; 66 } 67 68 } // namespace OHOS::UDMF