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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [rtems-20020807/] [cpukit/] [score/] [inline/] [rtems/] [score/] [coremutex.inl] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 1026 ivang
/*  inline/coremutex.inl
2
 *
3
 *  This include file contains all of the inlined routines associated
4
 *  with the CORE mutexes.
5
 *
6
 *  COPYRIGHT (c) 1989-1999.
7
 *  On-Line Applications Research Corporation (OAR).
8
 *
9
 *  The license and distribution terms for this file may be
10
 *  found in the file LICENSE in this distribution or at
11
 *  http://www.OARcorp.com/rtems/license.html.
12
 *
13
 *  coremutex.inl,v 1.13 2001/08/30 18:33:57 joel Exp
14
 */
15
 
16
#ifndef __INLINE_CORE_MUTEX_inl
17
#define __INLINE_CORE_MUTEX_inl
18
 
19
/*PAGE
20
 *
21
 *  _CORE_mutex_Is_locked
22
 *
23
 *  DESCRIPTION:
24
 *
25
 *  This routine returns TRUE if the mutex specified is locked and FALSE
26
 *  otherwise.
27
 */
28
 
29
RTEMS_INLINE_ROUTINE boolean _CORE_mutex_Is_locked(
30
  CORE_mutex_Control  *the_mutex
31
)
32
{
33
  return the_mutex->lock == CORE_MUTEX_LOCKED;
34
}
35
 
36
/*PAGE
37
 *
38
 *  _CORE_mutex_Is_fifo
39
 *
40
 *  DESCRIPTION:
41
 *
42
 *  This routine returns TRUE if the mutex's wait discipline is FIFO and FALSE
43
 *  otherwise.
44
 */
45
 
46
RTEMS_INLINE_ROUTINE boolean _CORE_mutex_Is_fifo(
47
  CORE_mutex_Attributes *the_attribute
48
)
49
{
50
  return the_attribute->discipline == CORE_MUTEX_DISCIPLINES_FIFO;
51
}
52
 
53
/*PAGE
54
 *
55
 *  _CORE_mutex_Is_priority
56
 *
57
 *  DESCRIPTION:
58
 *
59
 *  This routine returns TRUE if the mutex's wait discipline is PRIORITY and
60
 *  FALSE otherwise.
61
 */
62
 
63
RTEMS_INLINE_ROUTINE boolean _CORE_mutex_Is_priority(
64
  CORE_mutex_Attributes *the_attribute
65
)
66
{
67
  return the_attribute->discipline == CORE_MUTEX_DISCIPLINES_PRIORITY;
68
}
69
 
70
/*PAGE
71
 *
72
 *  _CORE_mutex_Is_inherit_priority
73
 *
74
 *  DESCRIPTION:
75
 *
76
 *  This routine returns TRUE if the mutex's wait discipline is
77
 *  INHERIT_PRIORITY and FALSE otherwise.
78
 */
79
 
80
RTEMS_INLINE_ROUTINE boolean _CORE_mutex_Is_inherit_priority(
81
  CORE_mutex_Attributes *the_attribute
82
)
83
{
84
  return the_attribute->discipline == CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT;
85
}
86
 
87
/*PAGE
88
 *
89
 *  _CORE_mutex_Is_priority_ceiling
90
 *
91
 *  DESCRIPTION:
92
 *
93
 *  This routine returns TRUE if the mutex's wait discipline is
94
 *  PRIORITY_CEILING and FALSE otherwise.
95
 */
96
 
97
RTEMS_INLINE_ROUTINE boolean _CORE_mutex_Is_priority_ceiling(
98
  CORE_mutex_Attributes *the_attribute
99
)
100
{
101
  return the_attribute->discipline == CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING;
102
}
103
 
104
/*PAGE
105
 *
106
 *  _CORE_mutex_Seize_interrupt_trylock
107
 *
108
 *  DESCRIPTION:
109
 *
110
 *  This routine returns 0 if "trylock" can resolve whether or not the
111
 *  mutex is immediately obtained or there was an error attempting to
112
 *  get it.  It returns 1 to indicate that the caller cannot obtain
113
 *  the mutex and will have to block to do so.
114
 *
115
 *  NOTE: There is no MACRO version of this routine.
116
 *        A body is in coremutexseize.c that is duplicated
117
 *        from the .inl by hand.
118
 */
119
 
120
RTEMS_INLINE_ROUTINE int _CORE_mutex_Seize_interrupt_trylock(
121
  CORE_mutex_Control  *the_mutex,
122
  ISR_Level           *level_p
123
)
124
{
125
  Thread_Control   *executing;
126
  ISR_Level         level = *level_p;
127
 
128
  /* disabled when you get here */
129
 
130
  executing = _Thread_Executing;
131
  executing->Wait.return_code = CORE_MUTEX_STATUS_SUCCESSFUL;
132
  if ( !_CORE_mutex_Is_locked( the_mutex ) ) {
133
    the_mutex->lock       = CORE_MUTEX_LOCKED;
134
    the_mutex->holder     = executing;
135
    the_mutex->holder_id  = executing->Object.id;
136
    the_mutex->nest_count = 1;
137
    if ( _CORE_mutex_Is_inherit_priority( &the_mutex->Attributes ) ||
138
         _CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) )
139
      executing->resource_count++;
140
    if ( !_CORE_mutex_Is_priority_ceiling( &the_mutex->Attributes ) ) {
141
        _ISR_Enable( level );
142
        return 0;
143
    }
144
    /* else must be CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING */
145
    {
146
       Priority_Control  ceiling;
147
       Priority_Control  current;
148
 
149
       ceiling = the_mutex->Attributes.priority_ceiling;
150
       current = executing->current_priority;
151
       if ( current == ceiling ) {
152
         _ISR_Enable( level );
153
         return 0;
154
       }
155
       if ( current > ceiling ) {
156
        _Thread_Disable_dispatch();
157
        _ISR_Enable( level );
158
        _Thread_Change_priority(
159
          the_mutex->holder,
160
          the_mutex->Attributes.priority_ceiling,
161
          FALSE
162
        );
163
        _Thread_Enable_dispatch();
164
        return 0;
165
      }
166
      /* if ( current < ceiling ) */ {
167
        executing->Wait.return_code = CORE_MUTEX_STATUS_CEILING_VIOLATED;
168
        the_mutex->nest_count = 0;     /* undo locking above */
169
        executing->resource_count--;   /* undo locking above */
170
        _ISR_Enable( level );
171
        return 0;
172
      }
173
    }
174
    return 0;
175
  }
176
 
177
  if ( _Thread_Is_executing( the_mutex->holder ) ) {
178
    switch ( the_mutex->Attributes.lock_nesting_behavior ) {
179
      case CORE_MUTEX_NESTING_ACQUIRES:
180
        the_mutex->nest_count++;
181
        _ISR_Enable( level );
182
        return 0;
183
      case CORE_MUTEX_NESTING_IS_ERROR:
184
        executing->Wait.return_code = CORE_MUTEX_STATUS_NESTING_NOT_ALLOWED;
185
        _ISR_Enable( level );
186
        return 0;
187
      case CORE_MUTEX_NESTING_BLOCKS:
188
        break;
189
    }
190
  }
191
 
192
  return 1;
193
}
194
 
195
#endif
196
/* end of include file */

powered by: WebSVN 2.1.0

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