source:
orxonox.OLD/trunk/src/lib/util/threading.h
@
7740
Last change on this file since 7740 was 7737, checked in by bensch, 19 years ago | |
---|---|
File size: 1.1 KB |
Rev | Line | |
---|---|---|
[4838] | 1 | /*! |
[7329] | 2 | * @file threading.h |
3 | * @brief Definition of Thread Classes. | |
4 | * | |
5 | * These are mainly Classes, that are used for wrapping around SDL_thread | |
[3245] | 6 | */ |
[1853] | 7 | |
[7329] | 8 | #ifndef _THREADING_H |
9 | #define _THREADING_H | |
[1853] | 10 | |
[7329] | 11 | #ifdef HAVE_SDL_H |
12 | #include <SDL_thread.h> | |
13 | #else | |
14 | #include <SDL/SDL_thread.h> | |
15 | #endif | |
[1853] | 16 | |
[7737] | 17 | namespace OrxThread |
[7331] | 18 | { |
[7737] | 19 | //! A class for Wrapping Threads |
20 | class Thread | |
21 | { | |
[3543] | 22 | |
[7737] | 23 | public: |
24 | Thread(); | |
25 | virtual ~Thread(); | |
[1853] | 26 | |
[3245] | 27 | |
[7737] | 28 | private: |
[3245] | 29 | |
[7737] | 30 | }; |
[1853] | 31 | |
[7737] | 32 | class Mutex |
33 | { | |
34 | public: | |
35 | Mutex() { this->mutex = SDL_CreateMutex(); }; | |
36 | ~Mutex() { SDL_DestroyMutex(this->mutex); } | |
[7331] | 37 | |
[7737] | 38 | void lock() { SDL_mutexP(mutex); }; |
39 | void unlock() { SDL_mutexV(mutex); }; | |
[7331] | 40 | |
[7737] | 41 | SDL_mutex* getMutex() const { return this->mutex; }; |
42 | private: | |
43 | SDL_mutex* mutex; | |
44 | }; | |
45 | ||
46 | //! A Class that locks a Mutex within its scope | |
47 | class MutexLock | |
48 | { | |
49 | public: | |
50 | //! Locks the Mutex mutex in this Scope. | |
51 | MutexLock(Mutex* mutex) { SDL_mutexP(mutex->getMutex()); this->mutex = mutex; }; | |
52 | ~MutexLock() { SDL_mutexV(mutex->getMutex()); }; | |
53 | private: | |
54 | Mutex* mutex; //!< The Mutex to lock. | |
55 | }; | |
56 | } | |
57 | ||
[7329] | 58 | #endif /* _THREADING_H */ |
Note: See TracBrowser
for help on using the repository browser.