Main Page | Namespace List | Class Hierarchy | Alphabetical List | Compound List | File List | Namespace Members | Compound Members | File Members

# thread-config.h

Go to the documentation of this file.

    00001 // Module:  Log4CPLUS
    00002 // File:    thread-config.h
    00003 // Created: 4/2003
    00004 // Author:  Tad E. Smith
    00005 //
    00006 //
    00007 // Copyright (C) Tad E. Smith  All rights reserved.
    00008 //
    00009 // This software is published under the terms of the Apache Software
    00010 // License version 1.1, a copy of which has been included with this
    00011 // distribution in the LICENSE.APL file.
    00012 //
    00013
    00016 #ifndef LOG4CPLUS_HELPERS_THREAD_CONFIG_HEADER_
    00017 #define LOG4CPLUS_HELPERS_THREAD_CONFIG_HEADER_
    00018
    00019
    00020 #ifdef LOG4CPLUS_USE_PTHREADS
    00021 #   include <pthread.h>
    00022 #   define LOG4CPLUS_MUTEX_PTR_DECLARE pthread_mutex_t*
    00023 #   define LOG4CPLUS_MUTEX_CREATE ::log4cplus::thread::createNewMutex()
    00024 #   define LOG4CPLUS_MUTEX_ASSIGN( mutex_a, mutex_b) mutex_a = mutex_b
    00025 #   define LOG4CPLUS_MUTEX_LOCK( mutex ) pthread_mutex_lock(mutex)
    00026 #   define LOG4CPLUS_MUTEX_UNLOCK( mutex ) pthread_mutex_unlock(mutex)
    00027 #   define LOG4CPLUS_MUTEX_FREE(mutex) ::log4cplus::thread::deleteMutex(mutex)
    00028 #   define LOG4CPLUS_THREAD_KEY_TYPE pthread_t
    00029 #   define LOG4CPLUS_GET_CURRENT_THREAD_NAME ::log4cplus::thread::getCurrentThreadName()
    00030
    00031 #   define LOG4CPLUS_GET_CURRENT_THREAD pthread_self()
    00032 #   define LOG4CPLUS_THREAD_LOCAL_TYPE pthread_key_t*
    00033 #   define LOG4CPLUS_THREAD_LOCAL_INIT ::log4cplus::thread::createPthreadKey()
    00034 #   define LOG4CPLUS_GET_THREAD_LOCAL_VALUE( key ) pthread_getspecific(*key)
    00035 #   define LOG4CPLUS_SET_THREAD_LOCAL_VALUE( key, value ) pthread_setspecific(*key, value)
    00036 #   define LOG4CPLUS_THREAD_LOCAL_CLEANUP( key ) pthread_key_delete(*key)
    00037 namespace log4cplus {
    00038     namespace thread {
    00039         LOG4CPLUS_MUTEX_PTR_DECLARE createNewMutex();
    00040         void deleteMutex(LOG4CPLUS_MUTEX_PTR_DECLARE);
    00041         LOG4CPLUS_THREAD_LOCAL_TYPE createPthreadKey();
    00042     }
    00043 }
    00044
    00045 #elif defined(LOG4CPLUS_USE_WIN32_THREADS)
    00046 #   include <windows.h>
    00047 #   define LOG4CPLUS_MUTEX_PTR_DECLARE CRITICAL_SECTION*
    00048 #   define LOG4CPLUS_MUTEX_CREATE ::log4cplus::thread::createNewMutex()
    00049 #   define LOG4CPLUS_MUTEX_ASSIGN( mutex_a, mutex_b) mutex_a = mutex_b
    00050 #   define LOG4CPLUS_MUTEX_LOCK( mutex )  EnterCriticalSection(mutex)
    00051 #   define LOG4CPLUS_MUTEX_UNLOCK( mutex )  LeaveCriticalSection(mutex)
    00052 #   define LOG4CPLUS_MUTEX_FREE(mutex) ::log4cplus::thread::deleteMutex(mutex)
    00053 #   define LOG4CPLUS_THREAD_KEY_TYPE  DWORD
    00054 #   define LOG4CPLUS_GET_CURRENT_THREAD  GetCurrentThreadId()
    00055 #   define LOG4CPLUS_GET_CURRENT_THREAD_NAME ::log4cplus::thread::getCurrentThreadName()
    00056 #   define LOG4CPLUS_THREAD_LOCAL_TYPE DWORD
    00057 #   define LOG4CPLUS_THREAD_LOCAL_INIT TlsAlloc()
    00058 #   define LOG4CPLUS_GET_THREAD_LOCAL_VALUE( key ) TlsGetValue(key)
    00059 #   define LOG4CPLUS_SET_THREAD_LOCAL_VALUE( key, value ) \
    00060        TlsSetValue(key, static_cast<LPVOID>(value))
    00061 #   define LOG4CPLUS_THREAD_LOCAL_CLEANUP( key ) TlsFree(key)
    00062 namespace log4cplus {
    00063     namespace thread {
    00064         LOG4CPLUS_EXPORT LOG4CPLUS_MUTEX_PTR_DECLARE createNewMutex();
    00065         LOG4CPLUS_EXPORT void deleteMutex(LOG4CPLUS_MUTEX_PTR_DECLARE);
    00066     }
    00067 }
    00068
    00069 #elif defined(LOG4CPLUS_SINGLE_THREADED)
    00070 #   define LOG4CPLUS_MUTEX_PTR_DECLARE int*
    00071 #   define LOG4CPLUS_MUTEX_CREATE NULL
    00072 #   define LOG4CPLUS_MUTEX_ASSIGN( mutex_a, mutex_b) mutex_a = mutex_b;
    00073 #   define LOG4CPLUS_MUTEX_LOCK( mutex )
    00074 #   define LOG4CPLUS_MUTEX_UNLOCK( mutex )
    00075 #   define LOG4CPLUS_MUTEX_FREE(mutex)
    00076 #   define LOG4CPLUS_THREAD_KEY_TYPE int
    00077 #   define LOG4CPLUS_GET_CURRENT_THREAD (int)1
    00078 #   define LOG4CPLUS_GET_CURRENT_THREAD_NAME "single"
    00079 #   define LOG4CPLUS_THREAD_LOCAL_TYPE void*
    00080 #   define LOG4CPLUS_THREAD_LOCAL_INIT NULL
    00081 #   define LOG4CPLUS_GET_THREAD_LOCAL_VALUE( key ) key
    00082 #   define LOG4CPLUS_SET_THREAD_LOCAL_VALUE( key, value ) key = value;
    00083 #   define LOG4CPLUS_THREAD_LOCAL_CLEANUP( key ) key = NULL
    00084
    00085 #else
    00086 #   error "You Must define a Threading model"
    00087 #endif
    00088
    00100 #ifndef LOG4CPLUS_SINGLE_THREADED
    00101 #  define LOG4CPLUS_BEGIN_SYNCHRONIZE_ON_MUTEX( mutex ) \
    00102              {::log4cplus::thread::Guard _sync_guard_object(mutex);
    00103 #else
    00104 #  define LOG4CPLUS_BEGIN_SYNCHRONIZE_ON_MUTEX( mutex ) {
    00105 #endif
    00106
    00107 #define LOG4CPLUS_END_SYNCHRONIZE_ON_MUTEX }
    00108
    00109
    00110 #endif // LOG4CPLUS_HELPERS_THREAD_CONFIG_HEADER_
    00111