1
0

Suggestions

This commit is contained in:
Tiger Wang 2014-10-23 23:58:01 +01:00
parent 27687cfcd4
commit 51fa6b4090
7 changed files with 50 additions and 10 deletions

View File

@ -14,7 +14,7 @@
/** Number of milliseconds per cycle */
#define CYCLE_MILLISECONDS 100
const int CYCLE_MILLISECONDS = 100;

View File

@ -184,7 +184,7 @@ template class SizeChecker<UInt16, 2>;
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
#define _WIN32_WINNT 0x501 // We want to target WinXP and higher
#define _WIN32_WINNT_WS03 // We want to target Windows XP with Service Pack 2 & Windows Server 2003 with Service Pack 1 and higher
#include <Windows.h>
#include <winsock2.h>
@ -239,7 +239,6 @@ template class SizeChecker<UInt16, 2>;
// STL stuff:
#include <thread>
#include <chrono>
#include <vector>
#include <list>

View File

@ -1,6 +1,7 @@
#pragma once
#include <mutex>
#include <thread>

View File

@ -11,6 +11,40 @@
#if defined(_MSC_VER) && defined(_DEBUG)
// Code adapted from MSDN: http://msdn.microsoft.com/en-us/library/xcb2z8hs.aspx
const DWORD MS_VC_EXCEPTION = 0x406D1388;
#pragma pack(push, 8)
struct THREADNAME_INFO
{
DWORD dwType; // Must be 0x1000.
LPCSTR szName; // Pointer to name (in user addr space).
DWORD dwThreadID; // Thread ID (-1 = caller thread).
DWORD dwFlags; // Reserved for future use, must be zero.
};
#pragma pack(pop)
/** Sets the name of a thread with the specified ID
(When in MSVC, the debugger provides "thread naming" by catching special exceptions)
*/
static void SetThreadName(std::thread * a_Thread, const char * a_ThreadName)
{
THREADNAME_INFO info { 0x1000, a_ThreadName, GetThreadId(a_Thread->native_handle()), 0 };
__try
{
RaiseException(MS_VC_EXCEPTION, 0, sizeof(info) / sizeof(ULONG_PTR), (ULONG_PTR *)&info);
}
__except (EXCEPTION_EXECUTE_HANDLER)
{
}
}
#endif // _MSC_VER && _DEBUG
////////////////////////////////////////////////////////////////////////////////
// cIsThread:
@ -39,11 +73,19 @@ bool cIsThread::Start(void)
try
{
m_Thread = std::thread(&cIsThread::Execute, this);
#if defined (_MSC_VER) && defined(_DEBUG)
if (!m_ThreadName.empty())
{
SetThreadName(&m_Thread, m_ThreadName.c_str());
}
#endif
return true;
}
catch (std::system_error & a_Exception)
{
LOGERROR("ERROR: Could not create thread \"%s\", error = %s!", m_ThreadName.c_str(), a_Exception.code(), a_Exception.what());
LOGERROR("cIsThread::Wait (std::thread) error %i: could not construct thread %s; %s", m_ThreadName.c_str(), a_Exception.code().value(), a_Exception.what());
return false;
}
}
@ -77,7 +119,7 @@ bool cIsThread::Wait(void)
}
catch (std::system_error & a_Exception)
{
LOGERROR("ERROR: Could wait for thread \"%s\" to finish, error = %s!", m_ThreadName.c_str(), a_Exception.code(), a_Exception.what());
LOGERROR("cIsThread::Wait (std::thread) error %i: could not join thread %s; %s", m_ThreadName.c_str(), a_Exception.code().value(), a_Exception.what());
return false;
}
}

View File

@ -16,8 +16,7 @@ In the descending class' constructor call the Start() method to start the thread
#pragma once
#ifndef CISTHREAD_H_INCLUDED
#define CISTHREAD_H_INCLUDED
#include <thread>
@ -56,5 +55,3 @@ protected:
#endif // CISTHREAD_H_INCLUDED

View File

@ -193,7 +193,7 @@ void cRoot::Start(void)
}
catch (std::system_error & a_Exception)
{
LOGERROR("ERROR: Could not create input thread, error = %s!", a_Exception.code(), a_Exception.what());
LOGERROR("cRoot::Start (std::thread) error %i: could not construct input thread; %s", a_Exception.code().value(), a_Exception.what());
}
#endif

View File

@ -6,6 +6,7 @@
#include "HTTPServer/HTTPServer.h"
#include "Defines.h"
#include "RankManager.h"
#include <thread>