/*! * @file threading.h * @brief Definition of Thread Classes. * * These are mainly Classes, that are used for wrapping around SDL_thread */ #ifndef _THREADING_H #define _THREADING_H #ifdef HAVE_SDL_H #include #else #include #endif namespace OrxThread { //! A class for Wrapping Threads class Thread { public: Thread(); virtual ~Thread(); private: }; class Mutex { public: Mutex() { this->mutex = SDL_CreateMutex(); }; ~Mutex() { SDL_DestroyMutex(this->mutex); } void lock() { SDL_mutexP(mutex); }; void unlock() { SDL_mutexV(mutex); }; SDL_mutex* getMutex() const { return this->mutex; }; private: SDL_mutex* mutex; }; //! A Class that locks a Mutex within its scope class MutexLock { public: //! Locks the Mutex mutex in this Scope. MutexLock(Mutex* mutex) { SDL_mutexP(mutex->getMutex()); this->mutex = mutex; }; ~MutexLock() { SDL_mutexV(mutex->getMutex()); }; private: Mutex* mutex; //!< The Mutex to lock. }; } #endif /* _THREADING_H */