status_monitor.cpp
Go to the documentation of this file.
1 /*
2  * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License").
5  * You may not use this file except in compliance with the License.
6  * A copy of the License is located at
7  *
8  * http://aws.amazon.com/apache2.0
9  *
10  * or in the "license" file accompanying this file. This file is distributed
11  * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12  * express or implied. See the License for the specific language governing
13  * permissions and limitations under the License.
14  */
15 
16 #include <numeric>
17 
19 
20 namespace Aws {
21 namespace DataFlow {
22 
23 void StatusMonitor::setStatus(const Status &status) {
24  status_ = status;
25  if (multi_status_cond_) {
26  multi_status_cond_->setStatus(status, this);
27  }
28 }
29 
31  if (hasWork()) {
32  std::lock_guard<std::mutex> lck(idle_mutex_);
33  work_condition_.notify_one();
34  }
35 }
36 
38  if (!hasWork()) {
39  std::unique_lock<std::mutex> lck(idle_mutex_);
40  work_condition_.wait(lck);
41  }
42 }
43 
44 std::cv_status ThreadMonitor::waitForWork(const std::chrono::microseconds& duration) {
45  std::cv_status status = std::cv_status::no_timeout;
46  if (!hasWork()) {
47  std::unique_lock<std::mutex> lck(idle_mutex_);
48  status = work_condition_.wait_for(lck, duration);
49  }
50  return status;
51 }
52 
54  std::shared_ptr<StatusMonitor> &status_monitor)
55 {
56  if (status_monitor) {
57  status_monitor->setStatusObserver(this);
58  status_monitors_[(status_monitor.get())] = mask_factory_.getNewMask();
59  setStatus(status_monitor->getStatus(), status_monitor.get());
60  }
61 }
62 
64  const Status &status, StatusMonitor *status_monitor) {
65  if (status == Status::AVAILABLE) {
66  mask_ |= status_monitors_[status_monitor];
67  } else {
68  mask_ &= ~status_monitors_[status_monitor];
69  }
70  notify();
71 }
72 
74  return mask_factory_.getCollectiveMask() == mask_;
75 }
76 
77 } // namespace DataFlow
78 } // namespace Aws
void setStatus(const Status &status)
MultiStatusConditionMonitor * multi_status_cond_
void addStatusMonitor(std::shared_ptr< StatusMonitor > &status_monitor)
virtual void setStatus(const Status &status, StatusMonitor *status_monitor)


dataflow_lite
Author(s): AWS RoboMaker
autogenerated on Fri May 7 2021 02:18:22