OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

thread.h
Go to the documentation of this file.
1 /* $Id: thread.h 27670 2016-10-30 17:29:33Z frosch $ */
2
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
9
12 #ifndef THREAD_H
13 #define THREAD_H
14
16 typedef void (*OTTDThreadFunc)(void *);
17
19 class OTTDThreadExitSignal { };
20
24 class ThreadObject {
25 public:
29 virtual ~ThreadObject() {};
30
34 virtual bool Exit() = 0;
35
39 virtual void Join() = 0;
40
50 static bool New(OTTDThreadFunc proc, void *param, ThreadObject **thread = NULL, const char *name = NULL);
51 };
52
56 class ThreadMutex {
57 public:
61 static ThreadMutex *New();
62
66 virtual ~ThreadMutex() {};
67
74 virtual void BeginCritical(bool allow_recursive = false) = 0;
75
82 virtual void EndCritical(bool allow_recursive = false) = 0;
83
90 virtual void WaitForSignal() = 0;
91
95 virtual void SendSignal() = 0;
96 };
97
101 class ThreadMutexLocker {
102 public:
107 ThreadMutexLocker(ThreadMutex *mutex) : mutex(mutex) { mutex->BeginCritical(); }
108
112 ~ThreadMutexLocker() { this->mutex->EndCritical(); }
113
114 private:
115 ThreadMutexLocker(const ThreadMutexLocker &) { NOT_REACHED(); }
116 ThreadMutexLocker &operator=(const ThreadMutexLocker &) { NOT_REACHED(); return *this; }
117 ThreadMutex *mutex;
118 };
119
124 uint GetCPUCoreCount();
125
126 #endif /* THREAD_H */