[revert] revert to the pre-lock version

This commit is contained in:
dijunkun
2025-11-28 11:44:08 +08:00
parent 9c1753c78c
commit feb9f2f460
5 changed files with 37 additions and 37 deletions

View File

@@ -90,7 +90,7 @@ int Render::RemoteWindow() {
target_remote_id = props.remote_id; target_remote_id = props.remote_id;
target_password = props.password; target_password = props.password;
{ {
std::shared_lock lock(client_properties_mutex_); // std::shared_lock lock(client_properties_mutex_);
if (client_properties_.find(remote_id) != if (client_properties_.find(remote_id) !=
client_properties_.end()) { client_properties_.end()) {
if (!client_properties_[remote_id]->connection_established_) { if (!client_properties_[remote_id]->connection_established_) {
@@ -126,7 +126,7 @@ int Render::RemoteWindow() {
if (elapsed >= 1000) { if (elapsed >= 1000) {
last_rejoin_check_time_ = now; last_rejoin_check_time_ = now;
need_to_rejoin_ = false; need_to_rejoin_ = false;
std::shared_lock lock(client_properties_mutex_); // std::shared_lock lock(client_properties_mutex_);
for (const auto& [_, props] : client_properties_) { for (const auto& [_, props] : client_properties_) {
if (props->rejoin_) { if (props->rejoin_) {
ConnectTo(props->remote_id_, props->remote_password_, ConnectTo(props->remote_id_, props->remote_password_,
@@ -161,17 +161,17 @@ int Render::ConnectTo(const std::string& remote_id, const char* password,
LOG_INFO("Connect to [{}]", remote_id); LOG_INFO("Connect to [{}]", remote_id);
focused_remote_id_ = remote_id; focused_remote_id_ = remote_id;
std::shared_lock shared_lock(client_properties_mutex_); // std::shared_lock shared_lock(client_properties_mutex_);
bool exists = bool exists =
(client_properties_.find(remote_id) != client_properties_.end()); (client_properties_.find(remote_id) != client_properties_.end());
shared_lock.unlock(); // shared_lock.unlock();
if (!exists) { if (!exists) {
PeerPtr* peer_to_init = nullptr; PeerPtr* peer_to_init = nullptr;
std::string local_id; std::string local_id;
{ {
std::unique_lock unique_lock(client_properties_mutex_); // std::unique_lock unique_lock(client_properties_mutex_);
if (client_properties_.find(remote_id) == client_properties_.end()) { if (client_properties_.find(remote_id) == client_properties_.end()) {
client_properties_[remote_id] = client_properties_[remote_id] =
std::make_shared<SubStreamWindowProperties>(); std::make_shared<SubStreamWindowProperties>();
@@ -208,7 +208,7 @@ int Render::ConnectTo(const std::string& remote_id, const char* password,
} }
int ret = -1; int ret = -1;
std::shared_lock read_lock(client_properties_mutex_); // std::shared_lock read_lock(client_properties_mutex_);
auto props = client_properties_[remote_id]; auto props = client_properties_[remote_id];
if (!props->connection_established_) { if (!props->connection_established_) {
props->remember_password_ = remember_password; props->remember_password_ = remember_password;
@@ -230,7 +230,7 @@ int Render::ConnectTo(const std::string& remote_id, const char* password,
} }
} }
} }
read_lock.unlock(); // read_lock.unlock();
return 0; return 0;
} }

View File

@@ -947,7 +947,7 @@ int Render::DrawStreamWindow() {
ImGui::Render(); ImGui::Render();
SDL_RenderClear(stream_renderer_); SDL_RenderClear(stream_renderer_);
std::shared_lock lock(client_properties_mutex_); // std::shared_lock lock(client_properties_mutex_);
for (auto& it : client_properties_) { for (auto& it : client_properties_) {
auto props = it.second; auto props = it.second;
if (props->tab_selected_) { if (props->tab_selected_) {
@@ -1285,7 +1285,7 @@ void Render::CleanupPeers() {
} }
{ {
std::shared_lock lock(client_properties_mutex_); // std::shared_lock lock(client_properties_mutex_);
for (auto& it : client_properties_) { for (auto& it : client_properties_) {
auto props = it.second; auto props = it.second;
CleanupPeer(props); CleanupPeer(props);
@@ -1293,7 +1293,7 @@ void Render::CleanupPeers() {
} }
{ {
std::unique_lock lock(client_properties_mutex_); // std::unique_lock lock(client_properties_mutex_);
client_properties_.clear(); client_properties_.clear();
} }
} }
@@ -1312,7 +1312,7 @@ void Render::CleanSubStreamWindowProperties(
} }
void Render::UpdateRenderRect() { void Render::UpdateRenderRect() {
std::shared_lock lock(client_properties_mutex_); // std::shared_lock lock(client_properties_mutex_);
for (auto& [_, props] : client_properties_) { for (auto& [_, props] : client_properties_) {
if (!props->reset_control_bar_pos_) { if (!props->reset_control_bar_pos_) {
props->mouse_diff_control_bar_pos_x_ = 0; props->mouse_diff_control_bar_pos_x_ = 0;
@@ -1388,7 +1388,7 @@ void Render::ProcessSdlEvent(const SDL_Event& event) {
DestroyStreamWindowContext(); DestroyStreamWindowContext();
{ {
std::shared_lock lock(client_properties_mutex_); // std::shared_lock lock(client_properties_mutex_);
for (auto& [host_name, props] : client_properties_) { for (auto& [host_name, props] : client_properties_) {
thumbnail_->SaveToThumbnail( thumbnail_->SaveToThumbnail(
(char*)props->dst_buffer_, props->video_width_, (char*)props->dst_buffer_, props->video_width_,
@@ -1419,7 +1419,7 @@ void Render::ProcessSdlEvent(const SDL_Event& event) {
} }
{ {
std::unique_lock lock(client_properties_mutex_); // std::unique_lock lock(client_properties_mutex_);
client_properties_.clear(); client_properties_.clear();
} }

View File

@@ -21,7 +21,7 @@ int Render::SendKeyCommand(int key_code, bool is_down) {
remote_action.k.key_value = key_code; remote_action.k.key_value = key_code;
if (!controlled_remote_id_.empty()) { if (!controlled_remote_id_.empty()) {
std::shared_lock lock(client_properties_mutex_); // std::shared_lock lock(client_properties_mutex_);
if (client_properties_.find(controlled_remote_id_) != if (client_properties_.find(controlled_remote_id_) !=
client_properties_.end()) { client_properties_.end()) {
auto props = client_properties_[controlled_remote_id_]; auto props = client_properties_[controlled_remote_id_];
@@ -45,7 +45,7 @@ int Render::ProcessMouseEvent(const SDL_Event& event) {
float ratio_x, ratio_y = 0; float ratio_x, ratio_y = 0;
RemoteAction remote_action; RemoteAction remote_action;
std::shared_lock lock(client_properties_mutex_); // std::shared_lock lock(client_properties_mutex_);
for (auto& it : client_properties_) { for (auto& it : client_properties_) {
auto props = it.second; auto props = it.second;
if (!props->control_mouse_) { if (!props->control_mouse_) {
@@ -162,7 +162,7 @@ void Render::SdlCaptureAudioIn(void* userdata, Uint8* stream, int len) {
} }
if (1) { if (1) {
std::shared_lock lock(render->client_properties_mutex_); // std::shared_lock lock(render->client_properties_mutex_);
for (const auto& it : render->client_properties_) { for (const auto& it : render->client_properties_) {
auto props = it.second; auto props = it.second;
if (props->connection_status_ == ConnectionStatus::Connected) { if (props->connection_status_ == ConnectionStatus::Connected) {
@@ -218,7 +218,7 @@ void Render::OnReceiveVideoBufferCb(const XVideoFrame* video_frame,
} }
std::string remote_id(user_id, user_id_size); std::string remote_id(user_id, user_id_size);
std::shared_lock lock(render->client_properties_mutex_); // std::shared_lock lock(render->client_properties_mutex_);
if (render->client_properties_.find(remote_id) == if (render->client_properties_.find(remote_id) ==
render->client_properties_.end()) { render->client_properties_.end()) {
return; return;
@@ -314,7 +314,7 @@ void Render::OnReceiveDataBufferCb(const char* data, size_t size,
} }
std::string remote_id(user_id, user_id_size); std::string remote_id(user_id, user_id_size);
std::shared_lock lock(render->client_properties_mutex_); // std::shared_lock lock(render->client_properties_mutex_);
if (render->client_properties_.find(remote_id) != if (render->client_properties_.find(remote_id) !=
render->client_properties_.end()) { render->client_properties_.end()) {
// local // local
@@ -386,7 +386,7 @@ void Render::OnSignalStatusCb(SignalStatus status, const char* user_id,
} }
std::string remote_id(client_id.begin() + 2, client_id.end()); std::string remote_id(client_id.begin() + 2, client_id.end());
std::shared_lock lock(render->client_properties_mutex_); // std::shared_lock lock(render->client_properties_mutex_);
if (render->client_properties_.find(remote_id) == if (render->client_properties_.find(remote_id) ==
render->client_properties_.end()) { render->client_properties_.end()) {
return; return;
@@ -416,7 +416,7 @@ void Render::OnConnectionStatusCb(ConnectionStatus status, const char* user_id,
if (!render) return; if (!render) return;
std::string remote_id(user_id, user_id_size); std::string remote_id(user_id, user_id_size);
std::shared_lock lock(render->client_properties_mutex_); // std::shared_lock lock(render->client_properties_mutex_);
auto it = render->client_properties_.find(remote_id); auto it = render->client_properties_.find(remote_id);
auto props = (it != render->client_properties_.end()) ? it->second : nullptr; auto props = (it != render->client_properties_.end()) ? it->second : nullptr;
@@ -577,7 +577,7 @@ void Render::NetStatusReport(const char* client_id, size_t client_id_size,
} }
std::string remote_id(user_id, user_id_size); std::string remote_id(user_id, user_id_size);
std::shared_lock lock(render->client_properties_mutex_); // std::shared_lock lock(render->client_properties_mutex_);
if (render->client_properties_.find(remote_id) == if (render->client_properties_.find(remote_id) ==
render->client_properties_.end()) { render->client_properties_.end()) {
return; return;

View File

@@ -32,7 +32,7 @@ int Render::MainWindow() {
StatusBar(); StatusBar();
if (show_connection_status_window_) { if (show_connection_status_window_) {
std::unique_lock lock(client_properties_mutex_); // std::unique_lock lock(client_properties_mutex_);
for (auto it = client_properties_.begin(); for (auto it = client_properties_.begin();
it != client_properties_.end();) { it != client_properties_.end();) {
auto& props = it->second; auto& props = it->second;

View File

@@ -32,7 +32,7 @@ void Render::DrawConnectionStatusText(
} }
void Render::CloseTab(decltype(client_properties_)::iterator& it) { void Render::CloseTab(decltype(client_properties_)::iterator& it) {
std::unique_lock lock(client_properties_mutex_); // std::unique_lock lock(client_properties_mutex_);
if (it != client_properties_.end()) { if (it != client_properties_.end()) {
CleanupPeer(it->second); CleanupPeer(it->second);
it = client_properties_.erase(it); it = client_properties_.erase(it);
@@ -82,21 +82,21 @@ int Render::StreamWindow() {
ImGuiTabBarFlags_AutoSelectNewTabs)) { ImGuiTabBarFlags_AutoSelectNewTabs)) {
is_tab_bar_hovered_ = ImGui::IsWindowHovered(); is_tab_bar_hovered_ = ImGui::IsWindowHovered();
std::shared_lock lock(client_properties_mutex_); // std::shared_lock lock(client_properties_mutex_);
for (auto it = client_properties_.begin(); for (auto it = client_properties_.begin();
it != client_properties_.end();) { it != client_properties_.end();) {
auto& props = it->second; auto& props = it->second;
if (!props->tab_opened_) { if (!props->tab_opened_) {
std::string remote_id_to_close = props->remote_id_; std::string remote_id_to_close = props->remote_id_;
lock.unlock(); // lock.unlock();
{ {
std::unique_lock unique_lock(client_properties_mutex_); // std::unique_lock unique_lock(client_properties_mutex_);
auto close_it = client_properties_.find(remote_id_to_close); auto close_it = client_properties_.find(remote_id_to_close);
if (close_it != client_properties_.end()) { if (close_it != client_properties_.end()) {
CloseTab(close_it); CloseTab(close_it);
} }
} }
lock.lock(); // lock.lock();
it = client_properties_.begin(); it = client_properties_.begin();
continue; continue;
} }
@@ -137,9 +137,9 @@ int Render::StreamWindow() {
if (!props->peer_) { if (!props->peer_) {
std::string remote_id_to_erase = props->remote_id_; std::string remote_id_to_erase = props->remote_id_;
lock.unlock(); // lock.unlock();
{ {
std::unique_lock unique_lock(client_properties_mutex_); // std::unique_lock unique_lock(client_properties_mutex_);
auto erase_it = client_properties_.find(remote_id_to_erase); auto erase_it = client_properties_.find(remote_id_to_erase);
if (erase_it != client_properties_.end()) { if (erase_it != client_properties_.end()) {
erase_it = client_properties_.erase(erase_it); erase_it = client_properties_.erase(erase_it);
@@ -150,7 +150,7 @@ int Render::StreamWindow() {
} }
} }
} }
lock.lock(); // lock.lock();
it = client_properties_.begin(); it = client_properties_.begin();
continue; continue;
} else { } else {
@@ -172,21 +172,21 @@ int Render::StreamWindow() {
ImGui::End(); // End TabBar ImGui::End(); // End TabBar
} else { } else {
std::shared_lock lock(client_properties_mutex_); // std::shared_lock lock(client_properties_mutex_);
for (auto it = client_properties_.begin(); for (auto it = client_properties_.begin();
it != client_properties_.end();) { it != client_properties_.end();) {
auto& props = it->second; auto& props = it->second;
if (!props->tab_opened_) { if (!props->tab_opened_) {
std::string remote_id_to_close = props->remote_id_; std::string remote_id_to_close = props->remote_id_;
lock.unlock(); // lock.unlock();
{ {
std::unique_lock unique_lock(client_properties_mutex_); // std::unique_lock unique_lock(client_properties_mutex_);
auto close_it = client_properties_.find(remote_id_to_close); auto close_it = client_properties_.find(remote_id_to_close);
if (close_it != client_properties_.end()) { if (close_it != client_properties_.end()) {
CloseTab(close_it); CloseTab(close_it);
} }
} }
lock.lock(); // lock.lock();
it = client_properties_.begin(); it = client_properties_.begin();
continue; continue;
} }
@@ -218,9 +218,9 @@ int Render::StreamWindow() {
fullscreen_button_pressed_ = false; fullscreen_button_pressed_ = false;
SDL_SetWindowFullscreen(stream_window_, false); SDL_SetWindowFullscreen(stream_window_, false);
std::string remote_id_to_erase = props->remote_id_; std::string remote_id_to_erase = props->remote_id_;
lock.unlock(); // lock.unlock();
{ {
std::unique_lock unique_lock(client_properties_mutex_); // std::unique_lock unique_lock(client_properties_mutex_);
auto erase_it = client_properties_.find(remote_id_to_erase); auto erase_it = client_properties_.find(remote_id_to_erase);
if (erase_it != client_properties_.end()) { if (erase_it != client_properties_.end()) {
client_properties_.erase(erase_it); client_properties_.erase(erase_it);
@@ -231,7 +231,7 @@ int Render::StreamWindow() {
} }
} }
} }
lock.lock(); // lock.lock();
it = client_properties_.begin(); it = client_properties_.begin();
continue; continue;
} else { } else {