reentrant.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*_############################################################################
  2. _##
  3. _## reentrant.h
  4. _##
  5. _## SNMP++v3.2.23
  6. _## -----------------------------------------------
  7. _## Copyright (c) 2001-2007 Jochen Katz, Frank Fock
  8. _##
  9. _## This software is based on SNMP++2.6 from Hewlett Packard:
  10. _##
  11. _## Copyright (c) 1996
  12. _## Hewlett-Packard Company
  13. _##
  14. _## ATTENTION: USE OF THIS SOFTWARE IS SUBJECT TO THE FOLLOWING TERMS.
  15. _## Permission to use, copy, modify, distribute and/or sell this software
  16. _## and/or its documentation is hereby granted without fee. User agrees
  17. _## to display the above copyright notice and this license notice in all
  18. _## copies of the software and any documentation of the software. User
  19. _## agrees to assume all liability for the use of the software;
  20. _## Hewlett-Packard and Jochen Katz make no representations about the
  21. _## suitability of this software for any purpose. It is provided
  22. _## "AS-IS" without warranty of any kind, either express or implied. User
  23. _## hereby grants a royalty-free license to any and all derivatives based
  24. _## upon this software code base.
  25. _##
  26. _## Stuttgart, Germany, Sun Nov 11 15:10:59 CET 2007
  27. _##
  28. _##########################################################################*/
  29. // $Id: reentrant.h 306 2007-09-14 20:01:45Z katz $
  30. #ifndef _reentrant_h_
  31. #define _reentrant_h_
  32. #include "snmp_pp/config_snmp_pp.h"
  33. #include "snmp_pp/smi.h"
  34. #ifdef _THREADS
  35. #ifdef WIN32
  36. #include <process.h>
  37. #elif defined (CPU) && CPU == PPC603
  38. #include <semLib.h>
  39. #else
  40. #include <pthread.h>
  41. #endif
  42. #endif
  43. #ifdef SNMP_PP_NAMESPACE
  44. namespace Snmp_pp {
  45. #endif
  46. class DLLOPT SnmpSynchronized {
  47. public:
  48. SnmpSynchronized();
  49. virtual ~SnmpSynchronized();
  50. #ifdef _THREADS
  51. #ifdef WIN32
  52. CRITICAL_SECTION _mutex;
  53. #elif defined (CPU) && CPU == PPC603
  54. SEM_ID _mutex;
  55. #else
  56. pthread_mutex_t _mutex;
  57. #endif
  58. #endif
  59. void lock();
  60. void unlock();
  61. };
  62. class DLLOPT SnmpSynchronize {
  63. public:
  64. SnmpSynchronize(SnmpSynchronized& sync) : s(sync) { s.lock(); };
  65. ~SnmpSynchronize() { s.unlock(); }
  66. protected:
  67. SnmpSynchronized& s;
  68. };
  69. #define REENTRANT(x) { SnmpSynchronize _synchronize(*this); x }
  70. #ifdef SNMP_PP_NAMESPACE
  71. } // end of namespace Snmp_pp
  72. #endif
  73. #endif