Use lock guards for mutex locking

This commit is contained in:
momo5502 2016-09-05 21:58:59 +02:00
parent d6ade55958
commit 8fb6ea0b63
6 changed files with 15 additions and 21 deletions

View File

@ -108,7 +108,7 @@ namespace Components
void Bans::LoadBans(Bans::BanList* list)
{
Bans::AccessMutex.lock();
std::lock_guard<std::mutex> _(Bans::AccessMutex);
FileSystem::File bans("bans.json");
@ -161,8 +161,6 @@ namespace Components
}
}
}
Bans::AccessMutex.unlock();
}
void Bans::BanClientNum(int num, std::string reason)

View File

@ -251,7 +251,7 @@ Logger::Print("Initializing BitMessage...\n");
}
// Resolve our own copy to the registered PubAddr copy in BitMRC if possible
auto resolvedAddress = FindPublicKey(address);
auto resolvedAddress = BitMessage::FindPublicKey(address);
if (resolvedAddress != nullptr &&
!resolvedAddress->waitingPubKey() && !resolvedAddress->getPubEncryptionKey().empty())
return true;
@ -261,7 +261,7 @@ Logger::Print("Initializing BitMessage...\n");
{
// Request public key
BitMessage::BMClient->getPubKey(address);
resolvedAddress = FindPublicKey(address);
resolvedAddress = BitMessage::FindPublicKey(address);
}
BitMessage::Save();

View File

@ -80,7 +80,7 @@ namespace Components
void Logger::Frame()
{
Logger::MessageMutex.lock();
std::lock_guard<std::mutex> _(Logger::MessageMutex);
for (unsigned int i = 0; i < Logger::MessageQueue.size(); ++i)
{
@ -93,7 +93,6 @@ namespace Components
}
Logger::MessageQueue.clear();
Logger::MessageMutex.unlock();
}
void Logger::PipeOutput(void(*callback)(std::string))

View File

@ -381,7 +381,7 @@ namespace Components
void ServerList::Insert(Network::Address address, Utils::InfoString info)
{
ServerList::RefreshContainer.Mutex.lock();
std::lock_guard<std::mutex> _(ServerList::RefreshContainer.Mutex);
for (auto i = ServerList::RefreshContainer.Servers.begin(); i != ServerList::RefreshContainer.Servers.end();)
{
@ -469,8 +469,6 @@ namespace Components
++i;
}
}
ServerList::RefreshContainer.Mutex.unlock();
}
ServerList::ServerInfo* ServerList::GetCurrentServer()
@ -625,7 +623,7 @@ namespace Components
ServerList::RefreshContainer.AwatingList = false;
ServerList::RefreshContainer.Mutex.lock();
std::lock_guard<std::mutex> _(ServerList::RefreshContainer.Mutex);
int offset = 0;
int count = ServerList::RefreshContainer.Servers.size();
@ -649,8 +647,6 @@ namespace Components
}
Logger::Print("Parsed %d servers from master\n", ServerList::RefreshContainer.Servers.size() - count);
ServerList::RefreshContainer.Mutex.unlock();
});
// Set default masterServerName + port and save it

View File

@ -17,6 +17,10 @@ Assert_Size(DWORD, 4);
Assert_Size(WORD, 2);
Assert_Size(BYTE, 1);
// 128 bit integers (only x64)
//Assert_Size(__int128, 16);
//Assert_Size(unsigned __int128, 16);
// 64 bit integers
Assert_Size(__int64, 8);
Assert_Size(unsigned __int64, 8);
@ -64,8 +68,8 @@ static_assert(sizeof(intptr_t) == 4 && sizeof(void*) == 4 && sizeof(size_t) == 4
// Disable telemetry data logging
extern "C"
{
void _cdecl __vcrt_initialize_telemetry_provider() {}
void _cdecl __telemetry_main_invoke_trigger() {}
void _cdecl __telemetry_main_return_trigger() {}
void _cdecl __vcrt_uninitialize_telemetry_provider() {}
void __cdecl __vcrt_initialize_telemetry_provider() {}
void __cdecl __telemetry_main_invoke_trigger() {}
void __cdecl __telemetry_main_return_trigger() {}
void __cdecl __vcrt_uninitialize_telemetry_provider() {}
};

View File

@ -136,11 +136,10 @@ namespace Utils
Hook* Hook::Install(bool unprotect, bool keepUnportected)
{
Hook::StateMutex.lock();
std::lock_guard<std::mutex> _(Hook::StateMutex);
if (!Hook::Initialized || Hook::Installed)
{
Hook::StateMutex.unlock();
return this;
}
@ -159,8 +158,6 @@ namespace Utils
FlushInstructionCache(GetCurrentProcess(), Hook::Place, sizeof(Hook::Buffer));
Hook::StateMutex.unlock();
return this;
}