Sophie

Sophie

distrib > * > 2009.0 > i586 > by-pkgid > 1f8d0d1e253a3f5aed78d2096c2df11f > files > 54

audiere-debug-1.9.4-7mdv2009.0.i586.rpm

/**
 * @file
 *
 * Internal platform-specific threads
 */

#ifndef THREADS_H
#define THREADS_H


#include "debug.h"


namespace audiere {

  typedef void (*AI_ThreadRoutine)(void* opaque);

  // threads
  bool AI_CreateThread(AI_ThreadRoutine routine, void* opaque, int priority = 0);

  // waiting
  void AI_Sleep(unsigned milliseconds);


  class Mutex {
  public:
    Mutex();
    ~Mutex();

    void lock();
    void unlock();

  private:
    struct Impl;
    Impl* m_impl;

    friend class CondVar;
  };


  class CondVar {
  public:
    CondVar();
    ~CondVar();

    void wait(Mutex& mutex, float seconds);
    void notify();

  private:
    struct Impl;
    Impl* m_impl;
  };


  class ScopedLock {
  public:
    ScopedLock(Mutex& mutex): m_mutex(mutex) {
      m_mutex.lock();
    }

    ScopedLock(Mutex* mutex): m_mutex(*mutex) {
      m_mutex.lock();
    }

    ~ScopedLock() {
      m_mutex.unlock();
    }

  private:
    Mutex& m_mutex;
  };


  #define SYNCHRONIZED(on) ScopedLock lock_obj__(on)

}

#endif