1 /* 2 * mt_support.h - multi-thread resource locking support declarations 3 */ 4 /* 5 * Author: Markku Laukkanen 6 * Created: 6-Sep-1999 7 * History: 8 * 8-Sep-1999 M. Slifcak method names changed; 9 * use array of resource locking structures. 10 */ 11 12 #ifndef MT_SUPPORT_H 13 #define MT_SUPPORT_H 14 15 #ifdef __cplusplus 16 extern "C" { 17 #endif 18 19 /* 20 * Lock group identifiers 21 */ 22 23 #define MT_LIBRARY_ID 0 24 #define MT_APPLICATION_ID 1 25 #define MT_TOKEN_ID 2 26 27 #define MT_MAX_IDS 3 /* one greater than last from above */ 28 #define MT_MAX_SUBIDS 10 29 30 31 /* 32 * Lock resource identifiers for library resources 33 */ 34 35 #define MT_LIB_NONE 0 36 #define MT_LIB_SESSION 1 37 #define MT_LIB_REQUESTID 2 38 #define MT_LIB_MESSAGEID 3 39 #define MT_LIB_SESSIONID 4 40 #define MT_LIB_TRANSID 5 41 42 #define MT_LIB_MAXIMUM 6 /* must be one greater than the last one */ 43 44 45 #if defined(NETSNMP_REENTRANT) || defined(WIN32) 46 47 #if HAVE_PTHREAD_H 48 #include <pthread.h> 49 typedef pthread_mutex_t mutex_type; 50 #ifdef pthread_mutexattr_default 51 #define MT_MUTEX_INIT_DEFAULT pthread_mutexattr_default 52 #else 53 #define MT_MUTEX_INIT_DEFAULT 0 54 #endif 55 56 #elif defined(WIN32) || defined(cygwin) 57 58 #include <windows.h> 59 typedef CRITICAL_SECTION mutex_type; 60 61 #else /* HAVE_PTHREAD_H */ 62 error "There is no re-entrant support as defined." 63 #endif /* HAVE_PTHREAD_H */ 64 65 66 NETSNMP_IMPORT 67 int snmp_res_init(void); 68 NETSNMP_IMPORT 69 int snmp_res_lock(int groupID, int resourceID); 70 NETSNMP_IMPORT 71 int snmp_res_unlock(int groupID, int resourceID); 72 NETSNMP_IMPORT 73 int snmp_res_destroy_mutex(int groupID, int resourceID); 74 75 #else /* NETSNMP_REENTRANT */ 76 77 #ifndef WIN32 78 #define snmp_res_init() do {} while (0) 79 #define snmp_res_lock(x,y) do {} while (0) 80 #define snmp_res_unlock(x,y) do {} while (0) 81 #define snmp_res_destroy_mutex(x,y) do {} while (0) 82 #endif /* WIN32 */ 83 84 #endif /* NETSNMP_REENTRANT */ 85 86 #ifdef __cplusplus 87 } 88 #endif 89 #endif /* MT_SUPPORT_H */ 90