summaryrefslogtreecommitdiff
path: root/src/thread.h
diff options
context:
space:
mode:
authortruebrain <truebrain@openttd.org>2008-06-08 12:06:27 +0000
committertruebrain <truebrain@openttd.org>2008-06-08 12:06:27 +0000
commitb95042b05cf7a8117309edc158df252f6f4adacb (patch)
tree824116881f6d5514cdaa069f10eddac84da3b04a /src/thread.h
parent96d7f87cc99ee04791b9fa097a027a17bb82226b (diff)
downloadopenttd-b95042b05cf7a8117309edc158df252f6f4adacb.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.h')
-rw-r--r--src/thread.h10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/thread.h b/src/thread.h
index f6f29a711..deaea0cd9 100644
--- a/src/thread.h
+++ b/src/thread.h
@@ -6,6 +6,7 @@
#define THREAD_H
typedef void (*OTTDThreadFunc)(void *);
+typedef void (*OTTDThreadTerminateFunc)(class ThreadObject *self);
/**
* A Thread Object which works on all our supported OSes.
@@ -56,9 +57,10 @@ public:
* with optinal params.
* @param proc The procedure to call inside the thread.
* @param param The params to give with 'proc'.
+ * @param terminate_func The function (or NULL) to call when the thread terminates.
* @return True if the thread was started correctly.
*/
- static ThreadObject *New(OTTDThreadFunc proc, void *param);
+ static ThreadObject *New(OTTDThreadFunc proc, void *param, OTTDThreadTerminateFunc terminate_func);
/**
* Convert the current thread to a new ThreadObject.
@@ -71,6 +73,12 @@ public:
* @return The thread ID of the current active thread.
*/
static uint CurrentId();
+
+ /**
+ * A OTTDThreadTerminateFunc, which cleans up the thread itself
+ * at termination of the thread (so it becomes self-managed).
+ */
+ static void TerminateCleanup(ThreadObject *self) { delete self; }
};
/**