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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [net/] [snmp/] [lib/] [v2_0/] [src/] [mt_support.c] - Blame information for rev 27

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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