reentrant.cpp
上传用户:ets1996
上传日期:2014-09-30
资源大小:353k
文件大小:2k
源码类别:

SNMP编程

开发平台:

Visual C++

  1. /*_############################################################################
  2.   _## 
  3.   _##  reentrant.cpp  
  4.   _##
  5.   _##  SNMP++v3.2.22
  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, Wed May  2 23:22:30 CEST 2007 
  27.   _##  
  28.   _##########################################################################*/
  29. char reentrant_cpp_version[]="#(@) SNMP++ $Id: reentrant.cpp 178 2005-09-19 19:59:36Z fock $";
  30. #include "snmp_pp/reentrant.h"
  31. #ifdef SNMP_PP_NAMESPACE
  32. namespace Snmp_pp {
  33. #endif
  34. SnmpSynchronized::SnmpSynchronized()
  35. {
  36. #ifdef _THREADS
  37. #ifdef WIN32
  38. InitializeCriticalSection(&_mutex);
  39. #elif defined (CPU) && CPU == PPC603
  40. _mutex = semMCreate(SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE );
  41. #else
  42. pthread_mutex_init(&_mutex, 0);
  43. #endif
  44. #endif
  45. }
  46. SnmpSynchronized::~SnmpSynchronized()
  47. {
  48. #ifdef _THREADS
  49. #ifdef WIN32
  50. DeleteCriticalSection(&_mutex);
  51. #elif defined (CPU) && CPU == PPC603
  52. semTake(_mutex, WAIT_FOREVER);
  53. semDelete(_mutex);
  54. #else
  55. pthread_mutex_destroy(&_mutex);
  56. #endif
  57. #endif
  58. }
  59. void SnmpSynchronized::lock()
  60. {
  61. #ifdef _THREADS
  62. #ifdef WIN32
  63. EnterCriticalSection(&_mutex);
  64. #elif defined (CPU) && CPU == PPC603
  65.     semTake(_mutex, WAIT_FOREVER);
  66. #else
  67. pthread_mutex_lock(&_mutex);
  68. #endif
  69. #endif
  70. }
  71. void SnmpSynchronized::unlock()
  72. {
  73. #ifdef _THREADS
  74. #ifdef WIN32
  75. LeaveCriticalSection(&_mutex);
  76. #elif defined (CPU) && CPU == PPC603
  77.     semGive(_mutex);
  78. #else
  79. pthread_mutex_unlock(&_mutex);
  80. #endif
  81. #endif
  82. }
  83. #ifdef SNMP_PP_NAMESPACE
  84. }; // end of namespace Snmp_pp
  85. #endif