mirror of
https://github.com/kunkundi/crossdesk.git
synced 2025-10-26 20:25:34 +08:00
[feat] lock the cache file when write/read it
This commit is contained in:
@@ -67,6 +67,7 @@ Render::Render() {}
|
|||||||
Render::~Render() {}
|
Render::~Render() {}
|
||||||
|
|
||||||
int Render::SaveSettingsIntoCacheFile() {
|
int Render::SaveSettingsIntoCacheFile() {
|
||||||
|
std::lock_guard<std::mutex> lock(cd_cache_mutex_);
|
||||||
cd_cache_file_ = fopen("cache.cd", "w+");
|
cd_cache_file_ = fopen("cache.cd", "w+");
|
||||||
if (!cd_cache_file_) {
|
if (!cd_cache_file_) {
|
||||||
return -1;
|
return -1;
|
||||||
@@ -87,12 +88,13 @@ int Render::SaveSettingsIntoCacheFile() {
|
|||||||
fwrite(&cd_cache_, sizeof(cd_cache_), 1, cd_cache_file_);
|
fwrite(&cd_cache_, sizeof(cd_cache_), 1, cd_cache_file_);
|
||||||
fclose(cd_cache_file_);
|
fclose(cd_cache_file_);
|
||||||
|
|
||||||
LOG_INFO("Save settings into cache file");
|
LOG_INFO("Save settings into cache file success");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int Render::LoadSettingsIntoCacheFile() {
|
int Render::LoadSettingsIntoCacheFile() {
|
||||||
|
std::lock_guard<std::mutex> lock(cd_cache_mutex_);
|
||||||
cd_cache_file_ = fopen("cache.cd", "r+");
|
cd_cache_file_ = fopen("cache.cd", "r+");
|
||||||
if (!cd_cache_file_) {
|
if (!cd_cache_file_) {
|
||||||
return -1;
|
return -1;
|
||||||
@@ -116,7 +118,7 @@ int Render::LoadSettingsIntoCacheFile() {
|
|||||||
(ConfigCenter::VIDEO_ENCODE_FORMAT)video_encode_format_button_value_);
|
(ConfigCenter::VIDEO_ENCODE_FORMAT)video_encode_format_button_value_);
|
||||||
config_center_.SetHardwareVideoCodec(enable_hardware_video_codec_);
|
config_center_.SetHardwareVideoCodec(enable_hardware_video_codec_);
|
||||||
|
|
||||||
LOG_INFO("Load settings into cache file");
|
LOG_INFO("Load settings from cache file");
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -402,10 +404,10 @@ int Render::Run() {
|
|||||||
while (!exit_) {
|
while (!exit_) {
|
||||||
if (SignalStatus::SignalConnected == signal_status_ &&
|
if (SignalStatus::SignalConnected == signal_status_ &&
|
||||||
!is_create_connection_) {
|
!is_create_connection_) {
|
||||||
|
LOG_INFO("Connected with signal server, create p2p connection");
|
||||||
is_create_connection_ =
|
is_create_connection_ =
|
||||||
CreateConnection(peer_, client_id_, password_saved_.c_str()) ? false
|
CreateConnection(peer_, client_id_, password_saved_.c_str()) ? false
|
||||||
: true;
|
: true;
|
||||||
LOG_INFO("Connected with signal server, create p2p connection");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!inited_ ||
|
if (!inited_ ||
|
||||||
|
|||||||
@@ -60,7 +60,7 @@ class Render {
|
|||||||
|
|
||||||
static void OnConnectionStatusCb(ConnectionStatus status, void *user_data);
|
static void OnConnectionStatusCb(ConnectionStatus status, void *user_data);
|
||||||
|
|
||||||
static void NetStatusReport(int TransmissionId, TraversalMode mode,
|
static void NetStatusReport(int client_id, TraversalMode mode,
|
||||||
const unsigned short send,
|
const unsigned short send,
|
||||||
const unsigned short receive, void *user_data);
|
const unsigned short receive, void *user_data);
|
||||||
|
|
||||||
@@ -101,6 +101,7 @@ class Render {
|
|||||||
private:
|
private:
|
||||||
FILE *cd_cache_file_ = nullptr;
|
FILE *cd_cache_file_ = nullptr;
|
||||||
CDCache cd_cache_;
|
CDCache cd_cache_;
|
||||||
|
std::mutex cd_cache_mutex_;
|
||||||
|
|
||||||
ConfigCenter config_center_;
|
ConfigCenter config_center_;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user