diff options
author | rubidium <rubidium@openttd.org> | 2009-09-01 10:07:22 +0000 |
---|---|---|
committer | rubidium <rubidium@openttd.org> | 2009-09-01 10:07:22 +0000 |
commit | 07d2af338e237889ff453a3a774522b9b0021439 (patch) | |
tree | 373ccc2eecf1aa917f24008e4d25535413dc4eb2 /src/thread/thread.h | |
parent | 5a3b2f0d02ddb7fedbca29a3e5e68dec28c887af (diff) | |
download | openttd-07d2af338e237889ff453a3a774522b9b0021439.tar.xz |
(svn r17339) -Codechange: move thread related files to their own directory (like done for video, music, sound, etc)
Diffstat (limited to 'src/thread/thread.h')
-rw-r--r-- | src/thread/thread.h | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/src/thread/thread.h b/src/thread/thread.h new file mode 100644 index 000000000..22873bee5 --- /dev/null +++ b/src/thread/thread.h @@ -0,0 +1,73 @@ +/* $Id$ */ + +/* + * This file is part of OpenTTD. + * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2. + * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>. + */ + +/** @file thread.h Base of all threads. */ + +#ifndef THREAD_H +#define THREAD_H + +typedef void (*OTTDThreadFunc)(void *); + +class OTTDThreadExitSignal { }; + +/** + * A Thread Object which works on all our supported OSes. + */ +class ThreadObject { +public: + /** + * Virtual destructor to allow 'delete' operator to work properly. + */ + virtual ~ThreadObject() {}; + + /** + * Exit this thread. + */ + virtual bool Exit() = 0; + + /** + * Join this thread. + */ + virtual void Join() = 0; + + /** + * Create a thread; proc will be called as first function inside the thread, + * with optinal params. + * @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. + * @return True if the thread was started correctly. + */ + static bool New(OTTDThreadFunc proc, void *param, ThreadObject **thread = NULL); +}; + +/** + * Cross-platform Mutex + */ +class ThreadMutex { +public: + static ThreadMutex *New(); + + /** + * Virtual Destructor to avoid compiler warnings. + */ + virtual ~ThreadMutex() {}; + + /** + * Begin the critical section + */ + virtual void BeginCritical() = 0; + + /** + * End of the critical section + */ + virtual void EndCritical() = 0; +}; + +#endif /* THREAD_H */ |