Android-cuttlefish cvd tool
Public Types | Public Member Functions | Static Public Member Functions | Private Attributes | List of all members
cuttlefish::HostModeCtrl Class Reference

#include <host_mode_ctrl.h>

Public Types

enum class  ModeType : std::uint8_t { kAndroidMode = 55 , kConfUI_Mode = 77 }
 

Public Member Functions

 INJECT (HostModeCtrl())
 
void WaitAndroidMode ()
 
void SetMode (const ModeType mode)
 
auto GetMode ()
 
auto IsConfirmatioUiMode ()
 
auto IsAndroidMode ()
 

Static Public Member Functions

static HostModeCtrlGet ()
 

Private Attributes

std::mutex mode_mtx_
 
std::condition_variable and_mode_cv_
 
std::condition_variable confui_mode_cv_
 
std::atomic< ModeTypeatomic_mode_
 

Detailed Description

mechanism to orchestrate concurrent executions of threads that work for screen connector

Within WebRTC service, it tells when it is now in the Android Mode or Confirmation UI mode

Member Enumeration Documentation

◆ ModeType

enum class cuttlefish::HostModeCtrl::ModeType : std::uint8_t
strong
Enumerator
kAndroidMode 
kConfUI_Mode 

Member Function Documentation

◆ Get()

static HostModeCtrl & cuttlefish::HostModeCtrl::Get ( )
inlinestatic

◆ GetMode()

auto cuttlefish::HostModeCtrl::GetMode ( )
inline

◆ INJECT()

cuttlefish::HostModeCtrl::INJECT ( HostModeCtrl()  )
inline

◆ IsAndroidMode()

auto cuttlefish::HostModeCtrl::IsAndroidMode ( )
inline

◆ IsConfirmatioUiMode()

auto cuttlefish::HostModeCtrl::IsConfirmatioUiMode ( )
inline

◆ SetMode()

void cuttlefish::HostModeCtrl::SetMode ( const ModeType  mode)
inline

◆ WaitAndroidMode()

void cuttlefish::HostModeCtrl::WaitAndroidMode ( )
inline

The thread that enqueues Android frames will call this to wait until the mode is kAndroidMode

Logically, using atomic_mode_ alone is not sufficient. Using mutex alone is logically complete but slow.

Note that most of the time, the mode is kAndroidMode. Also, note that this method is called at every single frame.

As an optimization, we check atomic_mode_ first. If failed, we wait for kAndroidMode with mutex-based lock

The actual synchronization is not at the and_mode_cv_.wait line but at this line: if (atomic_mode_ == ModeType::kAndroidMode) {

This trick reduces the flag checking delays by 70+% on a Gentoo based amd64 desktop, with Linux 5.10

Member Data Documentation

◆ and_mode_cv_

std::condition_variable cuttlefish::HostModeCtrl::and_mode_cv_
private

◆ atomic_mode_

std::atomic<ModeType> cuttlefish::HostModeCtrl::atomic_mode_
private

◆ confui_mode_cv_

std::condition_variable cuttlefish::HostModeCtrl::confui_mode_cv_
private

◆ mode_mtx_

std::mutex cuttlefish::HostModeCtrl::mode_mtx_
private

The documentation for this class was generated from the following file: