diff options
author | truebrain <truebrain@openttd.org> | 2008-06-08 12:06:27 +0000 |
---|---|---|
committer | truebrain <truebrain@openttd.org> | 2008-06-08 12:06:27 +0000 |
commit | e767b4f7784ba8e0f52cb920a4b171ef9b61e67f (patch) | |
tree | 824116881f6d5514cdaa069f10eddac84da3b04a /src/thread_win32.cpp | |
parent | 4657ae97fcd9487adb882f8634ad5cfe589d034c (diff) | |
download | openttd-e767b4f7784ba8e0f52cb920a4b171ef9b61e67f.tar.xz |
(svn r13412) -Add: OTTDThreadTerminateFunc, for all thread systems, which is called when a thread is terminated. Now GenWorld- and SaveLoad-thread cleanup theirselves correctly, while Fibers don't (as that causes access-violations)
Diffstat (limited to 'src/thread_win32.cpp')
-rw-r--r-- | src/thread_win32.cpp | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/src/thread_win32.cpp b/src/thread_win32.cpp index 6f12a6fbc..4ccd21e93 100644 --- a/src/thread_win32.cpp +++ b/src/thread_win32.cpp @@ -20,17 +20,19 @@ private: OTTDThreadFunc m_proc; void *m_param; bool m_attached; + OTTDThreadTerminateFunc m_terminate_func; public: /** * Create a win32 thread and start it, calling proc(param). */ - ThreadObject_Win32(OTTDThreadFunc proc, void *param) : + ThreadObject_Win32(OTTDThreadFunc proc, void *param, OTTDThreadTerminateFunc terminate_func) : m_id_thr(0), m_h_thr(NULL), m_proc(proc), m_param(param), - m_attached(false) + m_attached(false), + m_terminate_func(terminate_func) { m_h_thr = (HANDLE)_beginthreadex(NULL, 0, &stThreadProc, this, CREATE_SUSPENDED, &m_id_thr); if (m_h_thr == NULL) return; @@ -45,7 +47,8 @@ public: m_h_thr(NULL), m_proc(NULL), m_param(NULL), - m_attached(false) + m_attached(false), + m_terminate_func(NULL) { BOOL ret = DuplicateHandle(GetCurrentProcess(), GetCurrentThread(), GetCurrentProcess(), &m_h_thr, 0, FALSE, DUPLICATE_SAME_ACCESS); if (!ret) return; @@ -130,12 +133,14 @@ private: m_proc(m_param); } catch (...) { } + + if (this->m_terminate_func != NULL) this->m_terminate_func(this); } }; -/* static */ ThreadObject *ThreadObject::New(OTTDThreadFunc proc, void *param) +/* static */ ThreadObject *ThreadObject::New(OTTDThreadFunc proc, void *param, OTTDThreadTerminateFunc terminate_func) { - return new ThreadObject_Win32(proc, param); + return new ThreadObject_Win32(proc, param, terminate_func); } /* static */ ThreadObject* ThreadObject::AttachCurrent() |