mirror of
https://github.com/mod-playerbots/azerothcore-wotlk.git
synced 2026-01-15 10:00:28 +00:00
refactor(Core/Misc): add braces and impove codestyle (#6402)
This commit is contained in:
@@ -10,7 +10,7 @@
|
||||
#include <deque>
|
||||
#include <mutex>
|
||||
|
||||
template <class T, typename StorageType = std::deque<T> >
|
||||
template <class T, typename StorageType = std::deque<T>>
|
||||
class LockedQueue
|
||||
{
|
||||
//! Lock access to the queue.
|
||||
@@ -59,7 +59,9 @@ public:
|
||||
std::lock_guard<std::mutex> lock(_lock);
|
||||
|
||||
if (_queue.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
result = _queue.front();
|
||||
_queue.pop_front();
|
||||
@@ -73,11 +75,15 @@ public:
|
||||
std::lock_guard<std::mutex> lock(_lock);
|
||||
|
||||
if (_queue.empty())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
result = _queue.front();
|
||||
if (!check.Process(result))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
_queue.pop_front();
|
||||
return true;
|
||||
@@ -91,7 +97,9 @@ public:
|
||||
T& result = _queue.front();
|
||||
|
||||
if (autoUnlock)
|
||||
{
|
||||
unlock();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -45,7 +45,9 @@ public:
|
||||
std::lock_guard<std::mutex> lock(_queueLock);
|
||||
|
||||
if (_queue.empty() || _shutdown)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
value = _queue.front();
|
||||
|
||||
@@ -61,10 +63,14 @@ public:
|
||||
// we could be using .wait(lock, predicate) overload here but it is broken
|
||||
// https://connect.microsoft.com/VisualStudio/feedback/details/1098841
|
||||
while (_queue.empty() && !_shutdown)
|
||||
{
|
||||
_condition.wait(lock);
|
||||
}
|
||||
|
||||
if (_queue.empty() || _shutdown)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
value = _queue.front();
|
||||
|
||||
|
||||
@@ -31,20 +31,30 @@ void SetProcessPriority(std::string const& logChannel, uint32 affinity, bool hig
|
||||
ULONG_PTR currentAffinity = affinity & appAff;
|
||||
|
||||
if (!currentAffinity)
|
||||
{
|
||||
LOG_ERROR(logChannel, "Processors marked in UseProcessors bitmask (hex) %x are not accessible. Accessible processors bitmask (hex): %x", affinity, appAff);
|
||||
}
|
||||
else if (SetProcessAffinityMask(hProcess, currentAffinity))
|
||||
{
|
||||
LOG_INFO(logChannel, "Using processors (bitmask, hex): %x", currentAffinity);
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR(logChannel, "Can't set used processors (hex): %x", currentAffinity);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (highPriority)
|
||||
{
|
||||
if (SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS))
|
||||
{
|
||||
LOG_INFO(logChannel, "Process priority class set to HIGH");
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_ERROR(logChannel, "Can't set process priority class.");
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined(__linux__) // Linux
|
||||
@@ -56,10 +66,14 @@ void SetProcessPriority(std::string const& logChannel, uint32 affinity, bool hig
|
||||
|
||||
for (unsigned int i = 0; i < sizeof(affinity) * 8; ++i)
|
||||
if (affinity & (1 << i))
|
||||
{
|
||||
CPU_SET(i, &mask);
|
||||
}
|
||||
|
||||
if (sched_setaffinity(0, sizeof(mask), &mask))
|
||||
{
|
||||
LOG_ERROR(logChannel, "Can't set used processors (hex): %x, error: %s", affinity, strerror(errno));
|
||||
}
|
||||
else
|
||||
{
|
||||
CPU_ZERO(&mask);
|
||||
@@ -71,9 +85,13 @@ void SetProcessPriority(std::string const& logChannel, uint32 affinity, bool hig
|
||||
if (highPriority)
|
||||
{
|
||||
if (setpriority(PRIO_PROCESS, 0, PROCESS_HIGH_PRIORITY))
|
||||
{
|
||||
LOG_ERROR(logChannel, "Can't set process priority class, error: %s", strerror(errno));
|
||||
}
|
||||
else
|
||||
{
|
||||
LOG_INFO(logChannel, "Process priority class set to %i", getpriority(PRIO_PROCESS, 0));
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
@@ -25,7 +25,9 @@ Thread::Thread(Runnable* instance) : m_task(instance), m_ThreadImp(&Thread::Thre
|
||||
|
||||
// register reference to m_task to prevent it deeltion until destructor
|
||||
if (m_task)
|
||||
{
|
||||
m_task->incReference();
|
||||
}
|
||||
}
|
||||
|
||||
Thread::~Thread()
|
||||
@@ -34,13 +36,17 @@ Thread::~Thread()
|
||||
|
||||
// deleted runnable object (if no other references)
|
||||
if (m_task)
|
||||
{
|
||||
m_task->decReference();
|
||||
}
|
||||
}
|
||||
|
||||
bool Thread::wait()
|
||||
{
|
||||
if (m_iThreadId == std::thread::id() || !m_task)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool res = true;
|
||||
|
||||
@@ -61,7 +67,9 @@ bool Thread::wait()
|
||||
void Thread::destroy()
|
||||
{
|
||||
if (m_iThreadId == std::thread::id() || !m_task)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// FIXME: We need to make sure that all threads can be trusted to
|
||||
// halt execution on their own as this is not an interrupt
|
||||
|
||||
@@ -22,7 +22,9 @@ namespace Acore
|
||||
void decReference()
|
||||
{
|
||||
if (!--m_refs)
|
||||
{
|
||||
delete this;
|
||||
}
|
||||
}
|
||||
private:
|
||||
std::atomic_long m_refs;
|
||||
|
||||
Reference in New Issue
Block a user