forked from Ivasoft/DSView
fix: Language resouce can't surpports muti-thread
This commit is contained in:
@@ -430,6 +430,7 @@ void DecoderStack::do_decode_work()
|
||||
if (!dec->have_required_probes()) {
|
||||
_error_message = L_S(STR_PAGE_MSG, S_ID(IDS_MSG_DECODERSTACK_DECODE_WORK_ERROR),
|
||||
"One or more required channels have not been specified");
|
||||
dsv_err("ERROR:%s", _error_message.toStdString().c_str());
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -456,6 +457,7 @@ void DecoderStack::do_decode_work()
|
||||
{
|
||||
_error_message = L_S(STR_PAGE_MSG, S_ID(IDS_MSG_DECODERSTACK_DECODE_WORK_ERROR),
|
||||
"One or more required channels have not been specified");
|
||||
dsv_err("ERROR:%s", _error_message.toStdString().c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -86,6 +86,8 @@ const char *LangResource::get_lang_key(int lang)
|
||||
|
||||
bool LangResource::Load(int lang)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
|
||||
int num = sizeof(lang_id_keys) / sizeof(lang_key_item);
|
||||
const char *lan_name = get_lang_key(lang);
|
||||
|
||||
@@ -99,7 +101,7 @@ bool LangResource::Load(int lang)
|
||||
|
||||
_query_decoders.clear();
|
||||
|
||||
this->Release();
|
||||
release_self();
|
||||
|
||||
num = sizeof(lange_page_keys) / sizeof(lang_page_item);
|
||||
|
||||
@@ -117,6 +119,12 @@ bool LangResource::Load(int lang)
|
||||
|
||||
void LangResource::Release()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
release_self();
|
||||
}
|
||||
|
||||
void LangResource::release_self()
|
||||
{
|
||||
for (Lang_resource_page *p : _pages)
|
||||
{
|
||||
p->Clear();
|
||||
@@ -194,6 +202,8 @@ const char* LangResource::get_lang_text(int page_id, const char *str_id, const c
|
||||
assert(str_id);
|
||||
assert(default_str);
|
||||
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
|
||||
if (*str_id == '\0' || *default_str == '\0'){
|
||||
dsv_err("%s", "LangResource::get_lang_text(), param is empty.");
|
||||
assert(false);
|
||||
@@ -245,6 +255,8 @@ const char* LangResource::get_lang_text(int page_id, const char *str_id, const c
|
||||
|
||||
bool LangResource::is_new_decoder(const char *decoder_id)
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
|
||||
std::string key(decoder_id);
|
||||
if (_query_decoders.find(key) == _query_decoders.end()){
|
||||
_query_decoders[key] = 1;
|
||||
@@ -256,6 +268,8 @@ bool LangResource::is_new_decoder(const char *decoder_id)
|
||||
|
||||
void LangResource::reload_dynamic()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
|
||||
for (Lang_resource_page *p : _pages)
|
||||
{
|
||||
if (p->_is_dynamic){
|
||||
@@ -268,6 +282,8 @@ void LangResource::reload_dynamic()
|
||||
|
||||
void LangResource::release_dynamic()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_mutex);
|
||||
|
||||
for (Lang_resource_page *p : _pages)
|
||||
{
|
||||
if (p->_is_dynamic){
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
#include <QString>
|
||||
#include <string>
|
||||
#include "string_ids.h"
|
||||
#include <mutex>
|
||||
|
||||
struct lang_key_item
|
||||
{
|
||||
@@ -92,6 +93,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
void release_self();
|
||||
const char *get_lang_key(int lang);
|
||||
|
||||
void load_page(Lang_resource_page &p);
|
||||
@@ -103,6 +105,7 @@ private:
|
||||
Lang_resource_page *_current_page;
|
||||
int _cur_lang;
|
||||
std::map<std::string, int> _query_decoders;
|
||||
mutable std::mutex _mutex;
|
||||
};
|
||||
|
||||
#define S_ID(id) #id
|
||||
|
||||
Reference in New Issue
Block a user