Changeset - r9476:dfe3d556ae24
[Not reviewed]
master
0 7 0
rubidium - 16 years ago 2008-06-08 10:51:36
rubidium@openttd.org
(svn r13411) -Codechange: remove the return value from the thread procs because it is never used.
7 files changed with 19 insertions and 38 deletions:
0 comments (0 inline, 0 general)
src/fiber_thread.cpp
Show inline comments
 
@@ -106,13 +106,13 @@ public:
 
	}
 

	
 
private:
 
	/**
 
	 * First function which is called within the fiber.
 
	 */
 
	static void * CDECL stFiberProc(void *fiber)
 
	static void stFiberProc(void *fiber)
 
	{
 
		Fiber_Thread *cur = (Fiber_Thread *)fiber;
 
		/* Now suspend the thread until we get SwitchToFiber() for the first time */
 
		cur->m_sem->Wait();
 
		/* If we continue, we are the current thread */
 
		s_current = cur;
 
@@ -121,14 +121,12 @@ private:
 
			cur->m_proc(cur->m_param);
 
		} catch (...) {
 
			/* Unlock the main thread */
 
			s_main->m_sem->Set();
 
			throw;
 
		}
 

	
 
		return NULL;
 
	}
 
};
 

	
 
/* Initialize the static member of Fiber_Thread */
 
/* static */ Fiber_Thread *Fiber_Thread::s_current = NULL;
 
/* static */ Fiber_Thread *Fiber_Thread::s_main = NULL;
src/genworld.cpp
Show inline comments
 
@@ -82,13 +82,13 @@ bool IsGenerateWorldThreaded()
 
	return _gw.threaded && !_gw.quit_thread;
 
}
 

	
 
/**
 
 * The internal, real, generate function.
 
 */
 
static void * CDECL _GenerateWorld(void *arg)
 
static void _GenerateWorld(void *arg)
 
{
 
	try {
 
		_generating_world = true;
 
		if (_network_dedicated) DEBUG(net, 0, "Generating map, please wait...");
 
		/* Set the Random() seed to generation_seed so we produce the same map with the same seed */
 
		if (_settings_game.game_creation.generation_seed == GENERATE_NEW_SEED) _settings_game.game_creation.generation_seed = _settings_newgame.game_creation.generation_seed = InteractiveRandom();
 
@@ -167,13 +167,12 @@ static void * CDECL _GenerateWorld(void 
 

	
 
		if (_settings_client.gui.pause_on_newgame && _game_mode == GM_NORMAL) DoCommandP(0, 1, 0, NULL, CMD_PAUSE);
 
	} catch (...) {
 
		_generating_world = false;
 
		throw;
 
	}
 
	return NULL;
 
}
 

	
 
/**
 
 * Set here the function, if any, that you want to be called when landscape
 
 *  generation is done.
 
 */
src/saveload.cpp
Show inline comments
 
@@ -1604,16 +1604,15 @@ static SaveOrLoadResult SaveFileToDisk(b
 
			SaveFileError();
 
		}
 
		return SL_ERROR;
 
	}
 
}
 

	
 
static void * CDECL SaveFileToDiskThread(void *arg)
 
static void SaveFileToDiskThread(void *arg)
 
{
 
	SaveFileToDisk(true);
 
	return NULL;
 
}
 

	
 
void WaitTillSaved()
 
{
 
	if (_save_thread == NULL) return;
 

	
src/thread.h
Show inline comments
 
@@ -2,13 +2,13 @@
 

	
 
/** @file thread.h Base of all threads. */
 

	
 
#ifndef THREAD_H
 
#define THREAD_H
 

	
 
typedef void * (CDECL *OTTDThreadFunc)(void *);
 
typedef void (*OTTDThreadFunc)(void *);
 

	
 
/**
 
 * A Thread Object which works on all our supported OSes.
 
 */
 
class ThreadObject {
 
public:
 
@@ -34,13 +34,13 @@ public:
 
	 */
 
	virtual bool Exit() = 0;
 

	
 
	/**
 
	 * Join this thread.
 
	 */
 
	virtual void *Join() = 0;
 
	virtual void Join() = 0;
 

	
 
	/**
 
	 * Check if this thread is the current active thread.
 
	 * @return True if it is the current active thread.
 
	 */
 
	virtual bool IsCurrent() = 0;
src/thread_morphos.cpp
Show inline comments
 
@@ -31,13 +31,12 @@
 

	
 

	
 
struct OTTDThreadStartupMessage {
 
	struct Message msg;  ///< standard exec.library message (MUST be the first thing in the message struct!)
 
	OTTDThreadFunc func; ///< function the thread will execute
 
	void *arg;           ///< functions arguments for the thread function
 
	void *ret;           ///< return value of the thread function
 
};
 

	
 

	
 
/**
 
 *  Default OpenTTD STDIO/ERR debug output is not very useful for this, so we
 
 *  utilize serial/ramdebug instead.
 
@@ -76,13 +75,12 @@ public:
 
		/* Make sure main thread runs with sane priority */
 
		SetTaskPri(parent, 0);
 

	
 
		/* Things we'll pass down to the child by utilizing NP_StartupMsg */
 
		m_msg.func = proc;
 
		m_msg.arg  = param;
 
		m_msg.ret  = NULL;
 

	
 
		m_replyport = CreateMsgPort();
 

	
 
		if (m_replyport != NULL) {
 
			struct Process *child;
 

	
 
@@ -158,31 +156,26 @@ public:
 
			throw 0;
 
		}
 

	
 
		return true;
 
	}
 

	
 
	/* virtual */ void *Join()
 
	/* virtual */ void Join()
 
	{
 
		struct OTTDThreadStartupMessage *reply;
 
		void *ret;
 

	
 
		/* You cannot join yourself */
 
		assert(!IsCurrent());
 

	
 
		KPutStr("[OpenTTD] Join threads...\n");
 
		KPutStr("[OpenTTD] Wait for child to quit...\n");
 
		WaitPort(m_replyport);
 

	
 
		reply = (struct OTTDThreadStartupMessage *)GetMsg(m_replyport);
 
		ret   = reply->ret;
 

	
 
		GetMsg(m_replyport);
 
		DeleteMsgPort(m_replyport);
 
		m_thr = 0;
 

	
 
		return ret;
 
	}
 

	
 
	/* virtual */ bool IsCurrent()
 
	{
 
		return FindTask(NULL) == m_thr;
 
	}
 
@@ -206,13 +199,13 @@ private:
 
		SetTaskPri(child, -5);
 

	
 
		KPutStr("[Child] Progressing...\n");
 

	
 
		if (NewGetTaskAttrs(NULL, &msg, sizeof(struct OTTDThreadStartupMessage *), TASKINFOTYPE_STARTUPMSG, TAG_DONE) && msg != NULL) {
 
			try {
 
				msg->ret = msg->func(msg->arg);
 
				msg->func(msg->arg);
 
			} catch(...) {
 
				KPutStr("[Child] Returned to main()\n");
 
			}
 
		}
 

	
 
		/*  Quit the child, exec.library will reply the startup msg internally. */
 
@@ -253,13 +246,13 @@ public:
 
	{
 

	
 
	}
 

	
 
	/* virtual */ void Set()
 
	{
 
		// Check if semaphore count is really important there.
 
		/* Check if semaphore count is really important there. */
 
		ReleaseSemaphore(&m_sem);
 
	}
 

	
 
	/* virtual */ void Wait()
 
	{
 
		ObtainSemaphore(&m_sem);
src/thread_pthread.cpp
Show inline comments
 
@@ -92,24 +92,21 @@ public:
 
		if (!IsRunning()) return false;
 

	
 
		/* For now we terminate by throwing an error, gives much cleaner cleanup */
 
		throw 0;
 
	}
 

	
 
	/* virtual */ void *Join()
 
	/* virtual */ void Join()
 
	{
 
		/* You cannot join yourself */
 
		assert(!IsCurrent());
 

	
 
		void *ret;
 
		pthread_join(m_thr, &ret);
 
		pthread_join(m_thr, NULL);
 
		m_thr = 0;
 

	
 
		delete this;
 

	
 
		return ret;
 
	}
 

	
 
	/* virtual */ bool IsCurrent()
 
	{
 
		return pthread_self() == m_thr;
 
	}
 
@@ -123,20 +120,21 @@ private:
 
	/**
 
	 * On thread creation, this function is called, which calls the real startup
 
	 *  function. This to get back into the correct instance again.
 
	 */
 
	static void *stThreadProc(void *thr)
 
	{
 
		return ((ThreadObject_pthread *)thr)->ThreadProc();
 
		((ThreadObject_pthread *)thr)->ThreadProc();
 
		pthread_exit(NULL);
 
	}
 

	
 
	/**
 
	 * A new thread is created, and this function is called. Call the custom
 
	 *  function of the creator of the thread.
 
	 */
 
	void *ThreadProc()
 
	void ThreadProc()
 
	{
 
		/* The new thread stops here so the calling thread can complete pthread_create() call */
 
		sem_wait(&m_sem_start);
 

	
 
		/* Did this thread die naturally/via exit, or did it join? */
 
		bool exit = false;
 
@@ -149,14 +147,12 @@ private:
 
		}
 

	
 
		/* Notify threads waiting for our completion */
 
		sem_post(&m_sem_stop);
 

	
 
		if (exit) delete this;
 

	
 
		pthread_exit(NULL);
 
	}
 
};
 

	
 
/* static */ ThreadObject *ThreadObject::New(OTTDThreadFunc proc, void *param)
 
{
 
	return new ThreadObject_pthread(proc, param);
src/thread_win32.cpp
Show inline comments
 
@@ -17,13 +17,12 @@ class ThreadObject_Win32 : public Thread
 
private:
 
	uint     m_id_thr;
 
	HANDLE   m_h_thr;
 
	OTTDThreadFunc m_proc;
 
	void     *m_param;
 
	bool     m_attached;
 
	void     *ret;
 

	
 
public:
 
	/**
 
	 * Create a win32 thread and start it, calling proc(param).
 
	 */
 
	ThreadObject_Win32(OTTDThreadFunc proc, void *param) :
 
@@ -88,20 +87,18 @@ public:
 
		if (!IsRunning()) return false;
 

	
 
		/* For now we terminate by throwing an error, gives much cleaner cleanup */
 
		throw 0;
 
	}
 

	
 
	/* virtual */ void *Join()
 
	/* virtual */ void Join()
 
	{
 
		/* You cannot join yourself */
 
		assert(!IsCurrent());
 

	
 
		WaitForSingleObject(m_h_thr, INFINITE);
 

	
 
		return this->ret;
 
	}
 

	
 
	/* virtual */ bool IsCurrent()
 
	{
 
		DWORD id_cur = GetCurrentThreadId();
 
		return id_cur == m_id_thr;
 
@@ -116,27 +113,26 @@ private:
 
	/**
 
	 * On thread creation, this function is called, which calls the real startup
 
	 *  function. This to get back into the correct instance again.
 
	 */
 
	static uint CALLBACK stThreadProc(void *thr)
 
	{
 
		return ((ThreadObject_Win32 *)thr)->ThreadProc();
 
		((ThreadObject_Win32 *)thr)->ThreadProc();
 
		return 0;
 
	}
 

	
 
	/**
 
	 * A new thread is created, and this function is called. Call the custom
 
	 *  function of the creator of the thread.
 
	 */
 
	uint ThreadProc()
 
	void ThreadProc()
 
	{
 
		try {
 
			this->ret = m_proc(m_param);
 
			m_proc(m_param);
 
		} catch (...) {
 
		}
 

	
 
		return 0;
 
	}
 
};
 

	
 
/* static */ ThreadObject *ThreadObject::New(OTTDThreadFunc proc, void *param)
 
{
 
	return new ThreadObject_Win32(proc, param);
0 comments (0 inline, 0 general)