net-snmp 5.7
mt_support.h
00001 /*
00002  * mt_support.h - multi-thread resource locking support declarations 
00003  */
00004 /*
00005  * Author: Markku Laukkanen
00006  * Created: 6-Sep-1999
00007  * History:
00008  *  8-Sep-1999 M. Slifcak method names changed;
00009  *                        use array of resource locking structures.
00010  */
00011 
00012 #ifndef MT_SUPPORT_H
00013 #define MT_SUPPORT_H
00014 
00015 #ifdef __cplusplus
00016 extern          "C" {
00017 #endif
00018   
00019 /*
00020  * Lock group identifiers 
00021  */
00022 
00023 #define MT_LIBRARY_ID      0
00024 #define MT_APPLICATION_ID  1
00025 #define MT_TOKEN_ID        2
00026 
00027 #define MT_MAX_IDS         3    /* one greater than last from above */
00028 #define MT_MAX_SUBIDS      10
00029 
00030 
00031 /*
00032  * Lock resource identifiers for library resources 
00033  */
00034 
00035 #define MT_LIB_NONE        0
00036 #define MT_LIB_SESSION     1
00037 #define MT_LIB_REQUESTID   2
00038 #define MT_LIB_MESSAGEID   3
00039 #define MT_LIB_SESSIONID   4
00040 #define MT_LIB_TRANSID     5
00041 
00042 #define MT_LIB_MAXIMUM     6    /* must be one greater than the last one */
00043 
00044 
00045 #if defined(NETSNMP_REENTRANT) || defined(WIN32)
00046 
00047 #if HAVE_PTHREAD_H
00048 #include <pthread.h>
00049 typedef pthread_mutex_t mutex_type;
00050 #ifdef pthread_mutexattr_default
00051 #define MT_MUTEX_INIT_DEFAULT pthread_mutexattr_default
00052 #else
00053 #define MT_MUTEX_INIT_DEFAULT 0
00054 #endif
00055 
00056 #elif defined(WIN32) || defined(cygwin)
00057 
00058 #include <windows.h>
00059 typedef CRITICAL_SECTION mutex_type;
00060 
00061 #else  /*  HAVE_PTHREAD_H  */
00062 error "There is no re-entrant support as defined."
00063 #endif /*  HAVE_PTHREAD_H  */
00064 
00065 
00066 NETSNMP_IMPORT
00067 int             snmp_res_init(void);
00068 NETSNMP_IMPORT
00069 int             snmp_res_lock(int groupID, int resourceID);
00070 NETSNMP_IMPORT
00071 int             snmp_res_unlock(int groupID, int resourceID);
00072 NETSNMP_IMPORT
00073 int             snmp_res_destroy_mutex(int groupID, int resourceID);
00074 
00075 #else /*  NETSNMP_REENTRANT  */
00076 
00077 #ifndef WIN32
00078 #define snmp_res_init() do {} while (0)
00079 #define snmp_res_lock(x,y) do {} while (0)
00080 #define snmp_res_unlock(x,y) do {} while (0)
00081 #define snmp_res_destroy_mutex(x,y) do {} while (0)
00082 #endif /*  WIN32  */
00083 
00084 #endif /*  NETSNMP_REENTRANT  */
00085 
00086 #ifdef __cplusplus
00087 }
00088 #endif
00089 #endif /*  MT_SUPPORT_H  */