- Main Page
- Modules
- Classes
- Files
- Related Pages

# Mutex.h

    00001 /*****************************************************************************
    00002  * Author:   Vadim Zeitlin <vadim@wxwidgets.org>
    00003  *
    00004  *****************************************************************************
    00005  * Copyright (c) 2004 Vadim Zeitlin
    00006  *
    00007  * This library is free software; you can distribute it and/or modify it under
    00008  * the terms of the GNU Lesser General Public License (LGPL), as published by
    00009  * the Free Software Foundation; either version 2.1 of the License, or (at your
    00010  * option) any later version.
    00011  *
    00012  * This library is distributed in the hope that it will be useful, but WITHOUT
    00013  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    00014  * FITNESS FOR A PARTICULAR PURPOSE.  See the LGPL in the file COPYING for more
    00015  * details.
    00016  *
    00017  */
    00018
    00019 #ifndef _Mutex_incl_
    00020 #define _Mutex_incl_
    00021
    00022 #include <rlog/common.h>
    00023
    00024 #ifdef _WIN32
    00025     #include <windows.h>
    00026     // conflict with our own ERROR...
    00027     #undef ERROR
    00028
    00029     typedef CRITICAL_SECTION rlog_mutex_t;
    00030     #define rlog_mutex_init InitializeCriticalSection
    00031     #define rlog_mutex_destroy DeleteCriticalSection
    00032     #define rlog_mutex_lock EnterCriticalSection
    00033     #define rlog_mutex_unlock LeaveCriticalSection
    00034 #else
    00035     #include <pthread.h>
    00036
    00037     typedef pthread_mutex_t rlog_mutex_t;
    00038     #define rlog_mutex_init(m) pthread_mutex_init((m), 0)
    00039     #define rlog_mutex_destroy pthread_mutex_destroy
    00040     #define rlog_mutex_lock pthread_mutex_lock
    00041     #define rlog_mutex_unlock pthread_mutex_unlock
    00042 #endif
    00043
    00044 namespace rlog
    00045 {
    00053     class RLOG_DECL Mutex
    00054     {
    00055     public:
    00056         Mutex() { rlog_mutex_init(&m_mutex); }
    00057         ~Mutex() { rlog_mutex_destroy(&m_mutex); }
    00058
    00059         void Lock() { rlog_mutex_lock(&m_mutex); }
    00060         void Unlock() { rlog_mutex_unlock(&m_mutex); }
    00061
    00062     private:
    00063         rlog_mutex_t m_mutex;
    00064
    00065         Mutex( const Mutex & );
    00066         Mutex & operator = ( const Mutex & );
    00067     };
    00068 } // namespace rlog
    00069
    00070 #endif // _Mutex_incl_
    00071