Android-cuttlefish cvd tool
screen_connector_ctrl.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2020 The Android Open Source Project
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 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#pragma once
18
19#include <atomic>
20#include <condition_variable>
21#include <functional>
22#include <memory>
23#include <mutex>
24#include <thread>
25
27
28namespace cuttlefish {
39 public:
40 enum class ModeType { kAndroidMode, kConfUI_Mode };
41
43
66 return;
67 }
68 auto check = [this]() -> bool {
70 };
71 std::unique_lock<std::mutex> lock(mode_mtx_);
72 and_mode_cv_.wait(lock, check);
73 }
74
75 void SetMode(const ModeType mode) {
76 std::lock_guard<std::mutex> lock(mode_mtx_);
77 atomic_mode_ = mode;
79 and_mode_cv_.notify_all();
80 }
81 }
82
83 auto GetMode() {
84 std::lock_guard<std::mutex> lock(mode_mtx_);
85 ModeType ret_val = atomic_mode_;
86 return ret_val;
87 }
88
89 void SemWait() { sem_.SemWait(); }
90
91 // Only called by the producers
92 void SemPost() { sem_.SemPost(); }
93
94 private:
95 std::mutex mode_mtx_;
96 std::condition_variable and_mode_cv_;
97 std::atomic<ModeType> atomic_mode_;
98
99 // track the total number of items in all queues
101};
102
103} // namespace cuttlefish
Definition: screen_connector_ctrl.h:38
std::mutex mode_mtx_
Definition: screen_connector_ctrl.h:95
std::atomic< ModeType > atomic_mode_
Definition: screen_connector_ctrl.h:97
void WaitAndroidMode()
Definition: screen_connector_ctrl.h:64
std::condition_variable and_mode_cv_
Definition: screen_connector_ctrl.h:96
Semaphore sem_
Definition: screen_connector_ctrl.h:100
ScreenConnectorCtrl()
Definition: screen_connector_ctrl.h:42
ModeType
Definition: screen_connector_ctrl.h:40
auto GetMode()
Definition: screen_connector_ctrl.h:83
void SemWait()
Definition: screen_connector_ctrl.h:89
void SetMode(const ModeType mode)
Definition: screen_connector_ctrl.h:75
void SemPost()
Definition: screen_connector_ctrl.h:92
Definition: semaphore.h:23
void SemPost()
Definition: semaphore.h:35
void SemWait()
Definition: semaphore.h:28
#define check(p)
Definition: fec_private.h:203
Definition: alloc_utils.cpp:23