/**********************\************************************************* * * Copyright (C) 2006 Novell, Inc. All Rights Reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; version 2.1 * of the License. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, Novell, Inc. * * To contact Novell about this file by physical or electronic mail, * you may find current contact information at www.novell.com. * * Author: Juan Carlos Luciani * ***********************************************************************/ #ifndef _IPCINT_ #define _IPCINT_ //===[ Include files ]===================================================== #include #include #include #include #include using namespace std; extern "C" { #include #include #include #include #include #include #include #include #include #include #include #include #include #include // Ensure that NDEBUG is defined for release builds! #include #include } //===[ External data ]===================================================== extern int DebugLevel; extern bool UseSyslog; extern char appName[]; extern char *pAppName; extern pthread_mutex_t interlockedMutex; //===[ Macro definitions ]================================================= // // DbgTrace macro define // #define MAX_FORMAT_STRING_LEN 1024 #define DbgTrace(LEVEL, X, Y) { \ if (LEVEL == 0 || DebugLevel >= LEVEL) { \ if (UseSyslog) \ syslog(LOG_USER | LOG_INFO, X, Y); \ else { \ char *pFormatString = new char[MAX_FORMAT_STRING_LEN]; \ if (pFormatString) { \ snprintf(pFormatString, MAX_FORMAT_STRING_LEN, X, Y); \ fprintf(stderr, "%s -%s", appName, pFormatString); \ delete[] pFormatString; \ } \ } \ } \ } // // Interlocked Increment and Decrement macros // // Well, kind of interlocked :-). // __inline static unsigned long InterlockedIncrement(unsigned long *pValue) { unsigned long retVal; pthread_mutex_lock(&interlockedMutex); (*pValue) ++; retVal = *pValue; pthread_mutex_unlock(&interlockedMutex); return retVal; } __inline static unsigned long InterlockedDecrement(unsigned long *pValue) { unsigned long retVal; pthread_mutex_lock(&interlockedMutex); (*pValue) --; retVal = *pValue; pthread_mutex_unlock(&interlockedMutex); return retVal; } __inline static uint32_t InterlockedIncrement(uint32_t *pValue) { uint32_t retVal; pthread_mutex_lock(&interlockedMutex); (*pValue) ++; retVal = *pValue; pthread_mutex_unlock(&interlockedMutex); return retVal; } __inline static uint32_t InterlockedDecrement(uint32_t *pValue) { uint32_t retVal; pthread_mutex_lock(&interlockedMutex); (*pValue) --; retVal = *pValue; pthread_mutex_unlock(&interlockedMutex); return retVal; } //===[ Include files ]===================================================== //===[ External prototypes ]=============================================== //===[ Manifest constants ]================================================ //===[ Type definitions ]================================================== //===[ Function prototypes ]=============================================== #endif // _IPCINT_ //========================================================================= //=========================================================================