threads.h

Go to the documentation of this file.
00001 
00007 #ifndef THREADS_H
00008 #define THREADS_H
00009 
00010 
00011 #include "debug.h"
00012 
00013 
00014 namespace audiere {
00015 
00016   typedef void (*AI_ThreadRoutine)(void* opaque);
00017 
00018   // threads
00019   bool AI_CreateThread(AI_ThreadRoutine routine, void* opaque, int priority = 0);
00020 
00021   // waiting
00022   void AI_Sleep(unsigned milliseconds);
00023 
00024 
00025   class Mutex {
00026   public:
00027     Mutex();
00028     ~Mutex();
00029 
00030     void lock();
00031     void unlock();
00032 
00033   private:
00034     struct Impl;
00035     Impl* m_impl;
00036 
00037     friend class CondVar;
00038   };
00039 
00040 
00041   class CondVar {
00042   public:
00043     CondVar();
00044     ~CondVar();
00045 
00046     void wait(Mutex& mutex, float seconds);
00047     void notify();
00048 
00049   private:
00050     struct Impl;
00051     Impl* m_impl;
00052   };
00053 
00054 
00055   class ScopedLock {
00056   public:
00057     ScopedLock(Mutex& mutex): m_mutex(mutex) {
00058       m_mutex.lock();
00059     }
00060 
00061     ScopedLock(Mutex* mutex): m_mutex(*mutex) {
00062       m_mutex.lock();
00063     }
00064 
00065     ~ScopedLock() {
00066       m_mutex.unlock();
00067     }
00068 
00069   private:
00070     Mutex& m_mutex;
00071   };
00072 
00073 
00074   #define SYNCHRONIZED(on) ScopedLock lock_obj__(on)
00075 
00076 }
00077 
00078 #endif

Generated on Mon Feb 13 23:07:47 2006 for audiere by  doxygen 1.4.6