Merge branch 'cpp-11' into crashlog_improvements
# Conflicts: # config.lib
This commit is contained in:
@@ -44,9 +44,10 @@ public:
|
||||
* @param proc The procedure to call inside the thread.
|
||||
* @param param The params to give with 'proc'.
|
||||
* @param thread Place to store a pointer to the thread in. May be NULL.
|
||||
* @param name A name for the thread. May be NULL.
|
||||
* @return True if the thread was started correctly.
|
||||
*/
|
||||
static bool New(OTTDThreadFunc proc, void *param, ThreadObject **thread = NULL);
|
||||
static bool New(OTTDThreadFunc proc, void *param, ThreadObject **thread = NULL, const char *name = NULL);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@@ -193,7 +193,7 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
/* static */ bool ThreadObject::New(OTTDThreadFunc proc, void *param, ThreadObject **thread)
|
||||
/* static */ bool ThreadObject::New(OTTDThreadFunc proc, void *param, ThreadObject **thread, const char *name)
|
||||
{
|
||||
ThreadObject *to = new ThreadObject_MorphOS(proc, param, thread == NULL);
|
||||
if (thread != NULL) *thread = to;
|
||||
|
@@ -14,7 +14,7 @@
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
/* static */ bool ThreadObject::New(OTTDThreadFunc proc, void *param, ThreadObject **thread)
|
||||
/* static */ bool ThreadObject::New(OTTDThreadFunc proc, void *param, ThreadObject **thread, const char *name)
|
||||
{
|
||||
if (thread != NULL) *thread = NULL;
|
||||
return false;
|
||||
|
@@ -83,7 +83,7 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
/* static */ bool ThreadObject::New(OTTDThreadFunc proc, void *param, ThreadObject **thread)
|
||||
/* static */ bool ThreadObject::New(OTTDThreadFunc proc, void *param, ThreadObject **thread, const char *name)
|
||||
{
|
||||
ThreadObject *to = new ThreadObject_OS2(proc, param, thread == NULL);
|
||||
if (thread != NULL) *thread = to;
|
||||
|
@@ -25,16 +25,18 @@ private:
|
||||
OTTDThreadFunc proc; ///< External thread procedure.
|
||||
void *param; ///< Parameter for the external thread procedure.
|
||||
bool self_destruct; ///< Free ourselves when done?
|
||||
const char *name; ///< Name for the thread
|
||||
|
||||
public:
|
||||
/**
|
||||
* Create a pthread and start it, calling proc(param).
|
||||
*/
|
||||
ThreadObject_pthread(OTTDThreadFunc proc, void *param, bool self_destruct) :
|
||||
ThreadObject_pthread(OTTDThreadFunc proc, void *param, bool self_destruct, const char *name) :
|
||||
thread(0),
|
||||
proc(proc),
|
||||
param(param),
|
||||
self_destruct(self_destruct)
|
||||
self_destruct(self_destruct),
|
||||
name(name)
|
||||
{
|
||||
pthread_create(&this->thread, NULL, &stThreadProc, this);
|
||||
}
|
||||
@@ -60,7 +62,15 @@ private:
|
||||
*/
|
||||
static void *stThreadProc(void *thr)
|
||||
{
|
||||
((ThreadObject_pthread *)thr)->ThreadProc();
|
||||
ThreadObject_pthread *self = (ThreadObject_pthread *) thr;
|
||||
#if defined(__GLIBC__)
|
||||
#if __GLIBC_PREREQ(2, 12)
|
||||
if (self->name) {
|
||||
pthread_setname_np(pthread_self(), self->name);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
self->ThreadProc();
|
||||
pthread_exit(NULL);
|
||||
}
|
||||
|
||||
@@ -85,9 +95,9 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
/* static */ bool ThreadObject::New(OTTDThreadFunc proc, void *param, ThreadObject **thread)
|
||||
/* static */ bool ThreadObject::New(OTTDThreadFunc proc, void *param, ThreadObject **thread, const char *name)
|
||||
{
|
||||
ThreadObject *to = new ThreadObject_pthread(proc, param, thread == NULL);
|
||||
ThreadObject *to = new ThreadObject_pthread(proc, param, thread == NULL, name);
|
||||
if (thread != NULL) *thread = to;
|
||||
return true;
|
||||
}
|
||||
|
@@ -16,6 +16,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <windows.h>
|
||||
#include <process.h>
|
||||
#include "../os/windows/win32.h"
|
||||
|
||||
#include "../safeguards.h"
|
||||
|
||||
@@ -29,17 +30,19 @@ private:
|
||||
OTTDThreadFunc proc; ///< External thread procedure.
|
||||
void *param; ///< Parameter for the external thread procedure.
|
||||
bool self_destruct; ///< Free ourselves when done?
|
||||
const char *name; ///< Thread name.
|
||||
|
||||
public:
|
||||
/**
|
||||
* Create a win32 thread and start it, calling proc(param).
|
||||
*/
|
||||
ThreadObject_Win32(OTTDThreadFunc proc, void *param, bool self_destruct) :
|
||||
ThreadObject_Win32(OTTDThreadFunc proc, void *param, bool self_destruct, const char *name) :
|
||||
thread(NULL),
|
||||
id(0),
|
||||
proc(proc),
|
||||
param(param),
|
||||
self_destruct(self_destruct)
|
||||
self_destruct(self_destruct),
|
||||
name(name)
|
||||
{
|
||||
this->thread = (HANDLE)_beginthreadex(NULL, 0, &stThreadProc, this, CREATE_SUSPENDED, &this->id);
|
||||
if (this->thread == NULL) return;
|
||||
@@ -85,6 +88,10 @@ private:
|
||||
*/
|
||||
void ThreadProc()
|
||||
{
|
||||
#ifdef _MSC_VER
|
||||
/* Set thread name for debuggers. Has to be done from the thread due to a race condition in older MS debuggers. */
|
||||
SetWin32ThreadName(-1, this->name);
|
||||
#endif
|
||||
try {
|
||||
this->proc(this->param);
|
||||
} catch (OTTDThreadExitSignal) {
|
||||
@@ -96,9 +103,9 @@ private:
|
||||
}
|
||||
};
|
||||
|
||||
/* static */ bool ThreadObject::New(OTTDThreadFunc proc, void *param, ThreadObject **thread)
|
||||
/* static */ bool ThreadObject::New(OTTDThreadFunc proc, void *param, ThreadObject **thread, const char *name)
|
||||
{
|
||||
ThreadObject *to = new ThreadObject_Win32(proc, param, thread == NULL);
|
||||
ThreadObject *to = new ThreadObject_Win32(proc, param, thread == NULL, name);
|
||||
if (thread != NULL) *thread = to;
|
||||
return true;
|
||||
}
|
||||
|
Reference in New Issue
Block a user