/* -*-c++-*- header - Open Producer - Copyright (C) 2002 Don Burns
 * Distributed under the terms of the GNU LIBRARY GENERAL PUBLIC LICENSE (LGPL)
 * as published by the Free Software Foundation.
 */
#ifndef PRODUCER_MUTEX_H
#define PRODUCER_MUTEX_H 1

#include <Producer/Export>
#include <pthread.h>

#ifdef _USE_OPEN_THREAD // [

#include <OpenThread/Mutex.h>

namespace Producer {

class Mutex : public OpenThread::Mutex
{
    public:
        Mutex() : OpenThread::Mutex() {}
};

}

#else // ][
namespace Producer {

class Mutex {
    public:
    Mutex() { pthread_mutex_init( &_lock, 0L); }
    ~Mutex() { pthread_mutex_destroy( &_lock ); }
    void lock() { pthread_mutex_lock(  &_lock ); }
    bool test() { return pthread_mutex_trylock(&_lock) ? false : true; }
    void unlock() { pthread_mutex_unlock(  &_lock ); }

    private:
    pthread_mutex_t _lock;
};

}

#endif // ]

#endif
