]> git.stg.codes - ssmd.git/blob - 3rdparty/snmp++/src/reentrant.cpp
Fix build on osx.
[ssmd.git] / 3rdparty / snmp++ / src / reentrant.cpp
1 /*_############################################################################
2   _## 
3   _##  reentrant.cpp  
4   _##
5   _##  SNMP++v3.2.25
6   _##  -----------------------------------------------
7   _##  Copyright (c) 2001-2010 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, Thu Sep  2 00:07:47 CEST 2010 
27   _##  
28   _##########################################################################*/
29 char reentrant_cpp_version[]="#(@) SNMP++ $Id: reentrant.cpp 179 2005-09-19 19:59:36Z fock $";
30
31 #include "snmp_pp/reentrant.h"
32
33 #ifdef SNMP_PP_NAMESPACE
34 namespace Snmp_pp {
35 #endif
36
37 SnmpSynchronized::SnmpSynchronized()
38 {
39 #ifdef _THREADS
40 #ifdef WIN32
41         InitializeCriticalSection(&_mutex);
42 #elif defined (CPU) && CPU == PPC603
43         _mutex = semMCreate(SEM_Q_PRIORITY | SEM_DELETE_SAFE | SEM_INVERSION_SAFE );
44 #else
45         pthread_mutex_init(&_mutex, 0);
46 #endif
47 #endif
48 }
49
50 SnmpSynchronized::~SnmpSynchronized()
51 {
52 #ifdef _THREADS
53 #ifdef WIN32
54         DeleteCriticalSection(&_mutex);
55 #elif defined (CPU) && CPU == PPC603
56         semTake(_mutex, WAIT_FOREVER);
57         semDelete(_mutex);
58 #else
59         pthread_mutex_destroy(&_mutex);
60 #endif
61 #endif
62 }
63
64 void SnmpSynchronized::lock()
65 {
66 #ifdef _THREADS
67 #ifdef WIN32
68         EnterCriticalSection(&_mutex);
69 #elif defined (CPU) && CPU == PPC603
70     semTake(_mutex, WAIT_FOREVER);
71 #else
72         pthread_mutex_lock(&_mutex);
73 #endif
74 #endif
75 }       
76
77 void SnmpSynchronized::unlock()
78 {
79 #ifdef _THREADS
80 #ifdef WIN32
81         LeaveCriticalSection(&_mutex);
82 #elif defined (CPU) && CPU == PPC603
83     semGive(_mutex);
84 #else
85         pthread_mutex_unlock(&_mutex);
86 #endif
87 #endif
88 }       
89
90 #ifdef SNMP_PP_NAMESPACE
91 }; // end of namespace Snmp_pp
92 #endif 
93