OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [net/] [snmp/] [lib/] [current/] [src/] [mt_support.c] - Blame information for rev 786

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      ./lib/current/src/mt_support.c
4
//
5
//
6
//==========================================================================
7
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
8
// -------------------------------------------                              
9
// This file is part of eCos, the Embedded Configurable Operating System.   
10
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
11
//
12
// eCos is free software; you can redistribute it and/or modify it under    
13
// the terms of the GNU General Public License as published by the Free     
14
// Software Foundation; either version 2 or (at your option) any later      
15
// version.                                                                 
16
//
17
// eCos is distributed in the hope that it will be useful, but WITHOUT      
18
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
19
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
20
// for more details.                                                        
21
//
22
// You should have received a copy of the GNU General Public License        
23
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
24
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
25
//
26
// As a special exception, if other files instantiate templates or use      
27
// macros or inline functions from this file, or you compile this file      
28
// and link it with other works to produce a work based on this file,       
29
// this file does not by itself cause the resulting work to be covered by   
30
// the GNU General Public License. However the source code for this file    
31
// must still be made available in accordance with section (3) of the GNU   
32
// General Public License v2.                                               
33
//
34
// This exception does not invalidate any other reasons why a work based    
35
// on this file might be covered by the GNU General Public License.         
36
// -------------------------------------------                              
37
// ####ECOSGPLCOPYRIGHTEND####                                              
38
//####UCDSNMPCOPYRIGHTBEGIN####
39
//
40
// -------------------------------------------
41
//
42
// Portions of this software may have been derived from the UCD-SNMP
43
// project,  <http://ucd-snmp.ucdavis.edu/>  from the University of
44
// California at Davis, which was originally based on the Carnegie Mellon
45
// University SNMP implementation.  Portions of this software are therefore
46
// covered by the appropriate copyright disclaimers included herein.
47
//
48
// The release used was version 4.1.2 of May 2000.  "ucd-snmp-4.1.2"
49
// -------------------------------------------
50
//
51
//####UCDSNMPCOPYRIGHTEND####
52
//==========================================================================
53
//#####DESCRIPTIONBEGIN####
54
//
55
// Author(s):    hmt
56
// Contributors: hmt
57
// Date:         2000-05-30
58
// Purpose:      Port of UCD-SNMP distribution to eCos.
59
// Description:  
60
//              
61
//
62
//####DESCRIPTIONEND####
63
//
64
//==========================================================================
65
/********************************************************************
66
       Copyright 1989, 1991, 1992 by Carnegie Mellon University
67
 
68
                          Derivative Work -
69
Copyright 1996, 1998, 1999, 2000 The Regents of the University of California
70
 
71
                         All Rights Reserved
72
 
73
Permission to use, copy, modify and distribute this software and its
74
documentation for any purpose and without fee is hereby granted,
75
provided that the above copyright notice appears in all copies and
76
that both that copyright notice and this permission notice appear in
77
supporting documentation, and that the name of CMU and The Regents of
78
the University of California not be used in advertising or publicity
79
pertaining to distribution of the software without specific written
80
permission.
81
 
82
CMU AND THE REGENTS OF THE UNIVERSITY OF CALIFORNIA DISCLAIM ALL
83
WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
84
WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL CMU OR
85
THE REGENTS OF THE UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY SPECIAL,
86
INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
87
FROM THE LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
88
CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
89
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
90
*********************************************************************/
91
 
92
/* mt_support.c - multi-thread resource locking support */
93
/*
94
 * Author: Markku Laukkanen
95
 * Created: 6-Sep-1999
96
 * History:
97
 *  8-Sep-1999 M. Slifcak method names changed;
98
 *                        use array of resource locking structures.
99
 */
100
 
101
#include <config.h>
102
#include <errno.h>
103
#include "mt_support.h"
104
 
105
#ifdef __cplusplus
106
extern "C" {
107
#endif
108
 
109
#ifdef _REENTRANT
110
 
111
static
112
mutex_type s_res[MT_MAX_IDS][MT_LIB_MAXIMUM];  /* locking structures */
113
 
114
static mutex_type * _mt_res(int groupID, int resourceID)
115
{
116
    if (groupID < 1) return 0;
117
    if (groupID >= MT_MAX_IDS) return 0;
118
    if (resourceID < 1) return 0;
119
    if (resourceID >= MT_LIB_MAXIMUM) return 0;
120
    return (&s_res[groupID][resourceID]);
121
}
122
 
123
static
124
int snmp_res_init_mutex(mutex_type * mutex)
125
{
126
    int rc = 0;
127
#if HAVE_PTHREAD_H
128
    rc = pthread_mutex_init(mutex, MT_MUTEX_INIT_DEFAULT);
129
#elif defined(WIN32)
130
    InitializeCriticalSection(mutex);
131
#endif
132
 
133
    return rc;
134
}
135
 
136
int snmp_res_init(void)
137
{
138
    int ii, jj;
139
    int rc = 0;
140
    mutex_type *mutex;
141
 
142
  for (jj = 0; (0 == rc) && (jj < MT_MAX_IDS); jj++)
143
  for (ii = 0; (0 == rc) && (ii < MT_LIB_MAXIMUM); ii++)
144
  {
145
    mutex = _mt_res(jj, ii);
146
    if (!mutex) continue;
147
    rc = snmp_res_init_mutex( mutex );
148
  }
149
 
150
    return rc;
151
}
152
 
153
int snmp_res_destroy_mutex(int groupID, int resourceID)
154
{
155
    int rc = 0;
156
    mutex_type *mutex = _mt_res(groupID, resourceID);
157
    if (!mutex) return EFAULT;
158
 
159
#if HAVE_PTHREAD_H
160
    rc = pthread_mutex_destroy(mutex);
161
#elif defined(WIN32)
162
    DeleteCriticalSection(mutex);
163
#endif
164
 
165
    return rc;
166
}
167
 
168
int snmp_res_lock(int groupID, int resourceID)
169
{
170
    int rc = 0;
171
    mutex_type *mutex = _mt_res(groupID, resourceID);
172
    if (!mutex) return EFAULT;
173
 
174
#if HAVE_PTHREAD_H
175
    rc = pthread_mutex_lock(mutex);
176
#elif defined(WIN32)
177
    EnterCriticalSection(mutex);
178
#endif
179
 
180
    return rc;
181
}
182
 
183
int snmp_res_unlock(int groupID, int resourceID)
184
{
185
    int rc = 0;
186
    mutex_type *mutex = _mt_res(groupID, resourceID);
187
    if (!mutex) return EFAULT;
188
 
189
#if HAVE_PTHREAD_H
190
    rc = pthread_mutex_unlock(mutex);
191
#elif defined(WIN32)
192
    LeaveCriticalSection(mutex);
193
#endif
194
 
195
    return rc;
196
}
197
 
198
 
199
#else  /* !_REENTRANT */
200
 
201
#ifdef WIN32
202
 
203
/* Provide "do nothing" targets for Release (.DLL) builds. */
204
#undef snmp_res_init
205
#undef snmp_res_lock
206
#undef snmp_res_unlock
207
#undef snmp_res_destroy_mutex
208
 
209
int snmp_res_init(void) { return 0; }
210
int snmp_res_lock(int groupID, int resourceID) { return 0; }
211
int snmp_res_unlock(int groupID, int resourceID) { return 0; }
212
int snmp_res_destroy_mutex(int groupID, int resourceID) { return 0; }
213
#endif /* !WIN32 */
214
 
215
#endif /* !_REENTRANT */
216
 
217
 
218
#ifdef __cplusplus
219
};
220
#endif
221
 

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.