Program Listing for File mutex_w32.hpp

Return to documentation for file (/tmp/ws/src/ecl_core/ecl_threads/include/ecl/threads/mutex_w32.hpp)

/*****************************************************************************
** Ifdefs
*****************************************************************************/

#ifndef ECL_THREADS_MUTEX_W32_HPP_
#define ECL_THREADS_MUTEX_W32_HPP_

/*****************************************************************************
** Platform Check
*****************************************************************************/

#include <ecl/config/ecl.hpp>
#if defined(ECL_IS_WIN32)

/*****************************************************************************
** Includes
*****************************************************************************/

#include <windows.h>
#include <ecl/time/duration.hpp>
#include "macros.hpp"


/*****************************************************************************
** Namespaces
*****************************************************************************/

namespace ecl {

/*****************************************************************************
** Typedefs
*****************************************************************************/

typedef CRITICAL_SECTION RawMutex;
/*****************************************************************************
** Class Mutex
*****************************************************************************/
class ecl_threads_PUBLIC Mutex {
public:
    Mutex(const bool locked = false);
    virtual ~Mutex();

    void unlock();
    void lock();
    bool trylock(Duration &duration);
    bool trylock();
    unsigned int locks() { return number_locks; }

    RawMutex& rawType() { return mutex; }

private:
    RawMutex mutex;
    unsigned int number_locks;

};

} // namespace ecl


#endif /* ECL_IS_WIN32 */
#endif /* ECL_THREADS_MUTEX_W32_HPP_ */