1
0

Fixed Linux threading issues.

This commit is contained in:
madmaxoft 2013-09-21 20:44:16 +02:00
parent 744b3be454
commit c56bc4b01c
4 changed files with 8 additions and 17 deletions

View File

@ -53,11 +53,7 @@ static void SetThreadName( DWORD dwThreadID, LPCSTR szThreadName)
cIsThread::cIsThread(const AString & iThreadName) : cIsThread::cIsThread(const AString & iThreadName) :
m_ThreadName(iThreadName), m_ThreadName(iThreadName),
m_ShouldTerminate(false), m_ShouldTerminate(false),
#ifdef _WIN32 m_Handle(NULL)
m_Handle(NULL)
#else // _WIN32
m_HasStarted(false)
#endif // else _WIN32
{ {
} }
@ -77,9 +73,9 @@ cIsThread::~cIsThread()
bool cIsThread::Start(void) bool cIsThread::Start(void)
{ {
ASSERT(m_Handle == NULL); // Has already started one thread?
#ifdef _WIN32 #ifdef _WIN32
ASSERT(m_Handle == NULL); // Has already started one thread?
// Create the thread suspended, so that the mHandle variable is valid in the thread procedure // Create the thread suspended, so that the mHandle variable is valid in the thread procedure
DWORD ThreadID = 0; DWORD ThreadID = 0;
m_Handle = CreateThread(NULL, 0, thrExecute, this, CREATE_SUSPENDED, &ThreadID); m_Handle = CreateThread(NULL, 0, thrExecute, this, CREATE_SUSPENDED, &ThreadID);
@ -99,14 +95,11 @@ bool cIsThread::Start(void)
#endif // _DEBUG and _MSC_VER #endif // _DEBUG and _MSC_VER
#else // _WIN32 #else // _WIN32
ASSERT(!m_HasStarted);
if (pthread_create(&m_Handle, NULL, thrExecute, this)) if (pthread_create(&m_Handle, NULL, thrExecute, this))
{ {
LOGERROR("ERROR: Could not create thread \"%s\", !", m_ThreadName.c_str()); LOGERROR("ERROR: Could not create thread \"%s\", !", m_ThreadName.c_str());
return false; return false;
} }
m_HasStarted = true;
#endif // else _WIN32 #endif // else _WIN32
return true; return true;
@ -158,7 +151,6 @@ bool cIsThread::Wait(void)
LOGD("Thread %s finished", m_ThreadName.c_str()); LOGD("Thread %s finished", m_ThreadName.c_str());
#endif // LOGD #endif // LOGD
m_HasStarted = false;
return (res == 0); return (res == 0);
#endif // else _WIN32 #endif // else _WIN32
} }

View File

@ -48,7 +48,7 @@ public:
/// Returns the OS-dependent thread ID for the caller's thread /// Returns the OS-dependent thread ID for the caller's thread
static unsigned long GetCurrentID(void); static unsigned long GetCurrentID(void);
private: protected:
AString m_ThreadName; AString m_ThreadName;
#ifdef _WIN32 #ifdef _WIN32
@ -66,7 +66,6 @@ private:
#else // _WIN32 #else // _WIN32
pthread_t m_Handle; pthread_t m_Handle;
bool m_HasStarted;
static void * thrExecute(void * a_Param) static void * thrExecute(void * a_Param)
{ {

View File

@ -78,8 +78,8 @@ protected:
cRCONServer::cRCONServer(cServer & a_Server) : cRCONServer::cRCONServer(cServer & a_Server) :
m_Server(a_Server), m_Server(a_Server),
m_ListenThread4(*this, cSocket::IPv4, "RCON"), m_ListenThread4(*this, cSocket::IPv4, "RCON IPv4"),
m_ListenThread6(*this, cSocket::IPv6, "RCON") m_ListenThread6(*this, cSocket::IPv6, "RCON IPv6")
{ {
} }

View File

@ -103,8 +103,8 @@ void cServer::cTickThread::Execute(void)
// cServer: // cServer:
cServer::cServer(void) : cServer::cServer(void) :
m_ListenThreadIPv4(*this, cSocket::IPv4, "Client"), m_ListenThreadIPv4(*this, cSocket::IPv4, "Client IPv4"),
m_ListenThreadIPv6(*this, cSocket::IPv6, "Client"), m_ListenThreadIPv6(*this, cSocket::IPv6, "Client IPv6"),
m_bIsConnected(false), m_bIsConnected(false),
m_bRestarting(false), m_bRestarting(false),
m_RCONServer(*this), m_RCONServer(*this),