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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [cpukit/] [score/] [include/] [rtems/] [score/] [apimutex.h] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*  apimutex.h
2
 *
3
 *  This include file contains all the constants and structures associated
4
 *  with the API Mutex Handler.  This handler is used by API level
5
 *  routines to manage mutual exclusion.
6
 *
7
 *  COPYRIGHT (c) 1989-2002.
8
 *  On-Line Applications Research Corporation (OAR).
9
 *
10
 *  The license and distribution terms for this file may be
11
 *  found in the file LICENSE in this distribution or at
12
 *  http://www.OARcorp.com/rtems/license.html.
13
 *
14
 *  apimutex.h,v 1.2 2002/07/23 22:43:13 joel Exp
15
 */
16
 
17
#ifndef __API_MUTEX_h
18
#define __API_MUTEX_h
19
 
20
#ifdef __cplusplus
21
extern "C" {
22
#endif
23
 
24
#include <rtems/score/coremutex.h>
25
#include <rtems/score/isr.h>
26
#include <rtems/score/object.h>
27
 
28
/*
29
 *  The following defines the control block used to manage each mutex.
30
 */
31
 
32
typedef struct {
33
  Objects_Control       Object;
34
  CORE_mutex_Control    Mutex;
35
}   API_Mutex_Control;
36
 
37
/*
38
 *  The following defines the information control block used to manage
39
 *  this class of objects.
40
 */
41
 
42
SCORE_EXTERN Objects_Information  _API_Mutex_Information;
43
 
44
/*
45
 *  _API_Mutex_Initialization
46
 *
47
 *  DESCRIPTION:
48
 *
49
 *  This routine performs the initialization necessary for this handler.
50
 */
51
 
52
#if defined(RTEMS_MULTIPROCESSING)
53
#define _API_Mutex_Initialization( _maximum_mutexes ) \
54
  _Objects_Initialize_information( \
55
    &_API_Mutex_Information, \
56
    OBJECTS_INTERNAL_API, \
57
    OBJECTS_INTERNAL_MUTEXES, \
58
    _maximum_mutexes, \
59
    sizeof( API_Mutex_Control ), \
60
    FALSE, \
61
    0, \
62
    FALSE, \
63
    NULL \
64
  );
65
#else
66
#define _API_Mutex_Initialization( _maximum_mutexes ) \
67
  _Objects_Initialize_information( \
68
    &_API_Mutex_Information, \
69
    OBJECTS_INTERNAL_API, \
70
    OBJECTS_INTERNAL_MUTEXES, \
71
    _maximum_mutexes, \
72
    sizeof( API_Mutex_Control ), \
73
    FALSE, \
74
 
75
  );
76
#endif
77
 
78
/*
79
 *  _API_Mutex_Allocate
80
 *
81
 *  DESCRIPTION:
82
 *
83
 *  This routine allocates an api mutex from the inactive set.
84
 */
85
 
86
#define _API_Mutex_Allocate( _the_mutex ) \
87
  do { \
88
    CORE_mutex_Attributes attr =  \
89
      { CORE_MUTEX_NESTING_IS_ERROR, FALSE, \
90
        CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT, 0 }; \
91
    (_the_mutex) = (API_Mutex_Control *) \
92
      _Objects_Allocate( &_API_Mutex_Information ); \
93
    _CORE_mutex_Initialize( \
94
       &(_the_mutex)->Mutex, &attr, CORE_MUTEX_UNLOCKED ); \
95
  } while (0)
96
 
97
/*
98
 *  _API_Mutex_Lock
99
 *
100
 *  DESCRIPTION:
101
 *
102
 *  This routine acquires the specified api mutex.
103
 */
104
 
105
#define _API_Mutex_Lock( _the_mutex ) \
106
  do { \
107
    ISR_Level _level;  \
108
    _ISR_Disable( _level ); \
109
    _CORE_mutex_Seize( \
110
      &(_the_mutex)->Mutex, (_the_mutex)->Object.id, TRUE, 0, (_level) ); \
111
  } while (0)
112
 
113
/*
114
 *  _API_Mutex_Unlock
115
 *
116
 *  DESCRIPTION:
117
 *
118
 *  This routine releases the specified api mutex.
119
 */
120
 
121
#define _API_Mutex_Unlock( _the_mutex ) \
122
  do { \
123
    _Thread_Disable_dispatch(); \
124
      _CORE_mutex_Surrender( \
125
        &(_the_mutex)->Mutex, (_the_mutex)->Object.id, NULL ); \
126
    _Thread_Enable_dispatch(); \
127
  } while (0);
128
 
129
/*XXX when the APIs all use this for allocation and deallocation
130
 *XXX protection, then they should be renamed and probably moved
131
 */
132
 
133
SCORE_EXTERN API_Mutex_Control  *_RTEMS_Allocator_Mutex;
134
 
135
#define _RTEMS_Lock_allocator() \
136
  _API_Mutex_Lock( _RTEMS_Allocator_Mutex )
137
 
138
#define _RTEMS_Unlock_allocator() \
139
  _API_Mutex_Unlock( _RTEMS_Allocator_Mutex )
140
 
141
/*
142
 *  There are no inlines for this handler.
143
 */
144
 
145
#ifndef __RTEMS_APPLICATION__
146
/* #include <rtems/score/apimutex.inl> */
147
#endif
148
 
149
#ifdef __cplusplus
150
}
151
#endif
152
 
153
#endif
154
/*  end of include file */

powered by: WebSVN 2.1.0

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