• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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)19 void ProgressQueue::PushBack(ProgressInfo &progress)
20 {
21     std::lock_guard<std::mutex> lock(mutex_);
22     queue_.push(progress);
23 }
24 
Poll()25 std::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() const36 bool ProgressQueue::IsCancel() const
37 {
38     std::lock_guard<std::mutex> lock(mutex_);
39     return cancelFlag_;
40 }
41 
Cancel()42 void ProgressQueue::Cancel()
43 {
44     std::lock_guard<std::mutex> lock(mutex_);
45     cancelFlag_ = true;
46 }
47 
SetClearable(const bool clearableFlag)48 void ProgressQueue::SetClearable(const bool clearableFlag)
49 {
50     std::lock_guard<std::mutex> lock(mutex_);
51     clearableFlag_ = clearableFlag;
52 }
53 
Clear()54 bool ProgressQueue::Clear()
55 {
56     std::lock_guard<std::mutex> lock(mutex_);
57     auto oldClearableFlag = clearableFlag_;
58     clearableFlag_ = true;
59     return oldClearableFlag;
60 }
61 
IsClear() const62 bool ProgressQueue::IsClear() const
63 {
64     std::lock_guard<std::mutex> lock(mutex_);
65     return clearableFlag_;
66 }
67 
68 } // namespace OHOS::UDMF