Changeset - r22463:71520ac0d007
[Not reviewed]
master
0 13 0
frosch - 8 years ago 2016-10-30 17:29:33
frosch@openttd.org
(svn r27670) -Add: [FS#6471] Assign descriptive names to (GNU pthread) threads. (JGR)
13 files changed with 30 insertions and 19 deletions:
0 comments (0 inline, 0 general)
src/genworld.cpp
Show inline comments
 
@@ -331,7 +331,7 @@ void GenerateWorld(GenWorldMode mode, ui
 
		_gw.thread = NULL;
 
	}
 

	
 
	if (!VideoDriver::GetInstance()->HasGUI() || !ThreadObject::New(&_GenerateWorld, NULL, &_gw.thread)) {
 
	if (!VideoDriver::GetInstance()->HasGUI() || !ThreadObject::New(&_GenerateWorld, NULL, &_gw.thread, "ottd:genworld")) {
 
		DEBUG(misc, 1, "Cannot create genworld thread, reverting to single-threaded mode");
 
		_gw.threaded = false;
 
		_modal_progress_work_mutex->EndCritical();
src/linkgraph/linkgraphjob.cpp
Show inline comments
 
@@ -61,7 +61,7 @@ void LinkGraphJob::EraseFlows(NodeID fro
 
 */
 
void LinkGraphJob::SpawnThread()
 
{
 
	if (!ThreadObject::New(&(LinkGraphSchedule::Run), this, &this->thread)) {
 
	if (!ThreadObject::New(&(LinkGraphSchedule::Run), this, &this->thread, "ottd:linkgraph")) {
 
		this->thread = NULL;
 
		/* Of course this will hang a bit.
 
		 * On the other hand, if you want to play games which make this hang noticably
src/network/core/tcp_connect.cpp
Show inline comments
 
@@ -35,7 +35,7 @@ TCPConnecter::TCPConnecter(const Network
 
	address(address)
 
{
 
	*_tcp_connecters.Append() = this;
 
	if (!ThreadObject::New(TCPConnecter::ThreadEntry, this, &this->thread)) {
 
	if (!ThreadObject::New(TCPConnecter::ThreadEntry, this, &this->thread, "ottd:tcp")) {
 
		this->Connect();
 
	}
 
}
src/network/network_udp.cpp
Show inline comments
 
@@ -109,7 +109,7 @@ static void NetworkUDPQueryServerThread(
 
void NetworkUDPQueryServer(NetworkAddress address, bool manually)
 
{
 
	NetworkUDPQueryServerInfo *info = new NetworkUDPQueryServerInfo(address, manually);
 
	if (address.IsResolved() || !ThreadObject::New(NetworkUDPQueryServerThread, info)) {
 
	if (address.IsResolved() || !ThreadObject::New(NetworkUDPQueryServerThread, info, NULL, "ottd:udp-query")) {
 
		NetworkUDPQueryServerThread(info);
 
	}
 
}
 
@@ -565,7 +565,7 @@ void NetworkUDPRemoveAdvertise(bool bloc
 
	/* Check if we are advertising */
 
	if (!_networking || !_network_server || !_network_udp_server) return;
 

	
 
	if (blocking || !ThreadObject::New(NetworkUDPRemoveAdvertiseThread, NULL)) {
 
	if (blocking || !ThreadObject::New(NetworkUDPRemoveAdvertiseThread, NULL, NULL, "ottd:udp-advert")) {
 
		NetworkUDPRemoveAdvertiseThread(NULL);
 
	}
 
}
 
@@ -648,7 +648,7 @@ void NetworkUDPAdvertise()
 
	if (_next_advertisement < _last_advertisement) _next_advertisement = UINT32_MAX;
 
	if (_next_retry         < _last_advertisement) _next_retry         = UINT32_MAX;
 

	
 
	if (!ThreadObject::New(NetworkUDPAdvertiseThread, NULL)) {
 
	if (!ThreadObject::New(NetworkUDPAdvertiseThread, NULL, NULL, "ottd:udp-advert")) {
 
		NetworkUDPAdvertiseThread(NULL);
 
	}
 
}
src/newgrf_config.cpp
Show inline comments
 
@@ -786,7 +786,7 @@ void ScanNewGRFFiles(NewGRFScanCallback 
 
	/* Only then can we really start, especially by marking the whole screen dirty. Get those other windows hidden!. */
 
	MarkWholeScreenDirty();
 

	
 
	if (!VideoDriver::GetInstance()->HasGUI() || !ThreadObject::New(&DoScanNewGRFFiles, callback, NULL)) {
 
	if (!VideoDriver::GetInstance()->HasGUI() || !ThreadObject::New(&DoScanNewGRFFiles, callback, NULL, "ottd:newgrf-scan")) {
 
		_modal_progress_work_mutex->EndCritical();
 
		_modal_progress_paint_mutex->EndCritical();
 
		DoScanNewGRFFiles(callback);
src/saveload/saveload.cpp
Show inline comments
 
@@ -2585,7 +2585,7 @@ static SaveOrLoadResult DoSave(SaveFilte
 
	SlSaveChunks();
 

	
 
	SaveFileStart();
 
	if (!threaded || !ThreadObject::New(&SaveFileToDiskThread, NULL, &_save_thread)) {
 
	if (!threaded || !ThreadObject::New(&SaveFileToDiskThread, NULL, &_save_thread, "ottd:savegame")) {
 
		if (threaded) DEBUG(sl, 1, "Cannot create savegame thread, reverting to single-threaded mode...");
 

	
 
		SaveOrLoadResult result = SaveFileToDisk(false);
src/thread/thread.h
Show inline comments
 
@@ -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);
 
};
 

	
 
/**
src/thread/thread_morphos.cpp
Show inline comments
 
@@ -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;
src/thread/thread_none.cpp
Show inline comments
 
@@ -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;
src/thread/thread_os2.cpp
Show inline comments
 
@@ -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;
src/thread/thread_pthread.cpp
Show inline comments
 
@@ -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;
 
}
src/thread/thread_win32.cpp
Show inline comments
 
@@ -96,7 +96,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_Win32(proc, param, thread == NULL);
 
	if (thread != NULL) *thread = to;
src/video/sdl_v.cpp
Show inline comments
 
@@ -687,7 +687,7 @@ void VideoDriver_SDL::MainLoop()
 
			_draw_mutex->BeginCritical();
 
			_draw_continue = true;
 

	
 
			_draw_threaded = ThreadObject::New(&DrawSurfaceToScreenThread, NULL, &_draw_thread);
 
			_draw_threaded = ThreadObject::New(&DrawSurfaceToScreenThread, NULL, &_draw_thread, "ottd:draw-sdl");
 

	
 
			/* Free the mutex if we won't be able to use it. */
 
			if (!_draw_threaded) {
0 comments (0 inline, 0 general)