mt_support.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. #ifndef MT_SUPPORT_H
  12. #define MT_SUPPORT_H
  13. #ifdef __cplusplus
  14. extern "C" {
  15. #endif
  16. /*
  17. * Lock group identifiers
  18. */
  19. #define MT_LIBRARY_ID 0
  20. #define MT_APPLICATION_ID 1
  21. #define MT_TOKEN_ID 2
  22. #define MT_MAX_IDS 3 /* one greater than last from above */
  23. #define MT_MAX_SUBIDS 10
  24. /*
  25. * Lock resource identifiers for library resources
  26. */
  27. #define MT_LIB_NONE 0
  28. #define MT_LIB_SESSION 1
  29. #define MT_LIB_REQUESTID 2
  30. #define MT_LIB_MESSAGEID 3
  31. #define MT_LIB_SESSIONID 4
  32. #define MT_LIB_TRANSID 5
  33. #define MT_LIB_MAXIMUM 6 /* must be one greater than the last one */
  34. #if defined(NETSNMP_REENTRANT) || defined(WIN32)
  35. #ifdef HAVE_PTHREAD_H
  36. #include <pthread.h>
  37. typedef pthread_mutex_t mutex_type;
  38. #ifdef pthread_mutexattr_default
  39. #define MT_MUTEX_INIT_DEFAULT pthread_mutexattr_default
  40. #else
  41. #define MT_MUTEX_INIT_DEFAULT 0
  42. #endif
  43. #elif defined(WIN32) || defined(cygwin)
  44. #include <windows.h>
  45. typedef CRITICAL_SECTION mutex_type;
  46. #else /* HAVE_PTHREAD_H */
  47. error "There is no re-entrant support as defined."
  48. #endif /* HAVE_PTHREAD_H */
  49. NETSNMP_IMPORT
  50. int snmp_res_init(void);
  51. NETSNMP_IMPORT
  52. int snmp_res_lock(int groupID, int resourceID);
  53. NETSNMP_IMPORT
  54. int snmp_res_unlock(int groupID, int resourceID);
  55. NETSNMP_IMPORT
  56. int snmp_res_destroy_mutex(int groupID, int resourceID);
  57. #else /* NETSNMP_REENTRANT */
  58. #ifndef WIN32
  59. #define snmp_res_init() do {} while (0)
  60. #define snmp_res_lock(x,y) do {} while (0)
  61. #define snmp_res_unlock(x,y) do {} while (0)
  62. #define snmp_res_destroy_mutex(x,y) do {} while (0)
  63. #endif /* WIN32 */
  64. #endif /* NETSNMP_REENTRANT */
  65. #ifdef __cplusplus
  66. }
  67. #endif
  68. #endif /* MT_SUPPORT_H */