summaryrefslogtreecommitdiff
path: root/include/net-snmp/library/mt_support.h
blob: 4e35d3363c63f49750dc74822374fff54b5d7138 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
 * mt_support.h - multi-thread resource locking support declarations 
 */
/*
 * Author: Markku Laukkanen
 * Created: 6-Sep-1999
 * History:
 *  8-Sep-1999 M. Slifcak method names changed;
 *                        use array of resource locking structures.
 */

#ifndef MT_SUPPORT_H
#define MT_SUPPORT_H

#ifdef __cplusplus
extern          "C" {
#endif
  
/*
 * Lock group identifiers 
 */

#define MT_LIBRARY_ID      0
#define MT_APPLICATION_ID  1
#define MT_TOKEN_ID        2

#define MT_MAX_IDS         3    /* one greater than last from above */
#define MT_MAX_SUBIDS      10


/*
 * Lock resource identifiers for library resources 
 */

#define MT_LIB_NONE        0
#define MT_LIB_SESSION     1
#define MT_LIB_REQUESTID   2
#define MT_LIB_MESSAGEID   3
#define MT_LIB_SESSIONID   4
#define MT_LIB_TRANSID     5

#define MT_LIB_MAXIMUM     6    /* must be one greater than the last one */


#if defined(NETSNMP_REENTRANT) || defined(WIN32)

#if HAVE_PTHREAD_H
#include <pthread.h>
typedef pthread_mutex_t mutex_type;
#ifdef pthread_mutexattr_default
#define MT_MUTEX_INIT_DEFAULT pthread_mutexattr_default
#else
#define MT_MUTEX_INIT_DEFAULT 0
#endif

#elif defined(WIN32) || defined(cygwin)

#include <windows.h>
typedef CRITICAL_SECTION mutex_type;

#else  /*  HAVE_PTHREAD_H  */
error "There is no re-entrant support as defined."
#endif /*  HAVE_PTHREAD_H  */


NETSNMP_IMPORT
int             snmp_res_init(void);
NETSNMP_IMPORT
int             snmp_res_lock(int groupID, int resourceID);
NETSNMP_IMPORT
int             snmp_res_unlock(int groupID, int resourceID);
NETSNMP_IMPORT
int             snmp_res_destroy_mutex(int groupID, int resourceID);

#else /*  NETSNMP_REENTRANT  */

#ifndef WIN32
#define snmp_res_init() do {} while (0)
#define snmp_res_lock(x,y) do {} while (0)
#define snmp_res_unlock(x,y) do {} while (0)
#define snmp_res_destroy_mutex(x,y) do {} while (0)
#endif /*  WIN32  */

#endif /*  NETSNMP_REENTRANT  */

#ifdef __cplusplus
}
#endif
#endif /*  MT_SUPPORT_H  */