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

#include <screen_connector_ctrl.h>

Collaboration diagram for cuttlefish::ScreenConnectorCtrl:
Collaboration graph
[legend]

Public Types

enum class  ModeType { kAndroidMode , kConfUI_Mode }
 

Public Member Functions

 ScreenConnectorCtrl ()
 
void WaitAndroidMode ()
 
void SetMode (const ModeType mode)
 
auto GetMode ()
 
void SemWait ()
 
void SemPost ()
 

Private Attributes

std::mutex mode_mtx_
 
std::condition_variable and_mode_cv_
 
std::atomic< ModeTypeatomic_mode_
 
Semaphore sem_
 

Detailed Description

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

One thing is when any of wayland/socket-based connector or confirmation UI has a frame, it should wake up the consumer The two queues are separate, so the conditional variables, etc, can't be in the queue

Member Enumeration Documentation

◆ ModeType

Enumerator
kAndroidMode 
kConfUI_Mode 

Constructor & Destructor Documentation

◆ ScreenConnectorCtrl()

cuttlefish::ScreenConnectorCtrl::ScreenConnectorCtrl ( )
inline

Member Function Documentation

◆ GetMode()

auto cuttlefish::ScreenConnectorCtrl::GetMode ( )
inline

◆ SemPost()

void cuttlefish::ScreenConnectorCtrl::SemPost ( )
inline

◆ SemWait()

void cuttlefish::ScreenConnectorCtrl::SemWait ( )
inline

◆ SetMode()

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

◆ WaitAndroidMode()

void cuttlefish::ScreenConnectorCtrl::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::ScreenConnectorCtrl::and_mode_cv_
private

◆ atomic_mode_

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

◆ mode_mtx_

std::mutex cuttlefish::ScreenConnectorCtrl::mode_mtx_
private

◆ sem_

Semaphore cuttlefish::ScreenConnectorCtrl::sem_
private

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