source: rtems/c/src/exec/score/src/coremutexsurrender.c @ b3a6713

Last change on this file since b3a6713 was b3a6713, checked in by Joel Sherrill <joel.sherrill@…>, on Aug 16, 2001 at 9:36:15 PM

2001-08-16 Joel Sherrill <joel@…>

  • src/mqueuesendsupp.c: Account for possibly blocking during the core send operation.

2001-08-16 Joel Sherrill <joel@…>

  • src/msgqsubmit.c: Add a comment indicating that we do not have to account for possibly blocking during the core send operation because Classic API message queue send is always non-blocking.

2001-08-16 Joel Sherrill <joel@…>

  • include/rtems/score/coremsg.h, src/coremsgsubmit.c: Add a new return status to account for blocking sends. Otherwise, the caller will think that the returned message status will have the ultimate results of the operation. If the send times out, the final status will be in the return_code of the thread.

2001-08-16 Joel Sherrill <joel@…>

  • src/coremutexsurrender.c: Use holder thread not executing thread because even though they may and often are the same it is not guaranteed unless the proper attribute is set.

2001-08-16 Joel Sherrill <joel@…>

  • startup/linkcmds: Modified to work better with gcc 2.8.1 and gnat 3.13p.

2001-08-16 Joel Sherrill <joel@…>

  • tools/runtest.in: Recognize debug variant of monitor test.

2001-08-16 Joel Sherrill <joel@…>

  • sp13/sp13.scn: Id in screen had wrong class field value.
  • sp13/system.h: Account for message buffer memory.
  • sp13/task2.c: Remove unnecessary check for failure.

2001-08-16 Joel Sherrill <joel@…>

  • sp20/system.h: Account for extra task stacks properly.

2001-08-16 Joel Sherrill <joel@…>

  • include/tmacros.h: Attempt to print errno as further information.
  • Property mode set to 100644
File size: 4.1 KB
Line 
1/*
2 *  Mutex Handler
3 *
4 *  DESCRIPTION:
5 *
6 *  This package is the implementation of the Mutex Handler.
7 *  This handler provides synchronization and mutual exclusion capabilities.
8 *
9 *  COPYRIGHT (c) 1989-1999.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.OARcorp.com/rtems/license.html.
15 *
16 *  $Id$
17 */
18
19#include <rtems/system.h>
20#include <rtems/score/isr.h>
21#include <rtems/score/coremutex.h>
22#include <rtems/score/states.h>
23#include <rtems/score/thread.h>
24#include <rtems/score/threadq.h>
25
26/*
27 *  _CORE_mutex_Surrender
28 *
29 *  DESCRIPTION:
30 *
31 *  This routine frees a unit to the mutex.  If a task was blocked waiting for
32 *  a unit from this mutex, then that task will be readied and the unit
33 *  given to that task.  Otherwise, the unit will be returned to the mutex.
34 *
35 *  Input parameters:
36 *    the_mutex            - the mutex to be flushed
37 *    id                   - id of parent mutex
38 *    api_mutex_mp_support - api dependent MP support actions
39 *
40 *  Output parameters:
41 *    CORE_MUTEX_STATUS_SUCCESSFUL - if successful
42 *    core error code              - if unsuccessful
43 */
44
45CORE_mutex_Status _CORE_mutex_Surrender(
46  CORE_mutex_Control                *the_mutex,
47  Objects_Id                         id,
48  CORE_mutex_API_mp_support_callout  api_mutex_mp_support
49)
50{
51  Thread_Control *the_thread;
52  Thread_Control *holder;
53
54  holder    = the_mutex->holder;
55
56  /*
57   *  The following code allows a thread (or ISR) other than the thread
58   *  which acquired the mutex to release that mutex.  This is only
59   *  allowed when the mutex in quetion is FIFO or simple Priority
60   *  discipline.  But Priority Ceiling or Priority Inheritance mutexes
61   *  must be released by the thread which acquired them.
62   */ 
63
64  if ( the_mutex->Attributes.only_owner_release ) {
65    if ( !_Thread_Is_executing( holder ) )
66      return( CORE_MUTEX_STATUS_NOT_OWNER_OF_RESOURCE );
67  }
68
69  /* XXX already unlocked -- not right status */
70
71  if ( !the_mutex->nest_count ) 
72    return( CORE_MUTEX_STATUS_SUCCESSFUL );
73
74  the_mutex->nest_count--;
75
76  if ( the_mutex->nest_count != 0 ) {
77    switch ( the_mutex->Attributes.lock_nesting_behavior ) {
78      case CORE_MUTEX_NESTING_ACQUIRES:
79        return CORE_MUTEX_STATUS_SUCCESSFUL;
80      case CORE_MUTEX_NESTING_IS_ERROR:
81        /* should never occur */
82        return CORE_MUTEX_STATUS_NESTING_NOT_ALLOWED;
83      case CORE_MUTEX_NESTING_BLOCKS:
84        /* Currently no API exercises this behavior. */
85        break;
86    }
87  }
88
89  holder->resource_count--;
90  the_mutex->holder    = NULL;
91  the_mutex->holder_id = 0;
92
93  /*
94   *  Whether or not someone is waiting for the mutex, an
95   *  inherited priority must be lowered if this is the last
96   *  mutex (i.e. resource) this task has.
97   */
98
99  switch ( the_mutex->Attributes.discipline ) {
100    case CORE_MUTEX_DISCIPLINES_FIFO:
101    case CORE_MUTEX_DISCIPLINES_PRIORITY:
102      break;
103    case CORE_MUTEX_DISCIPLINES_PRIORITY_CEILING:
104    case CORE_MUTEX_DISCIPLINES_PRIORITY_INHERIT:
105      if ( holder->resource_count == 0 && 
106           holder->real_priority != holder->current_priority ) {
107         _Thread_Change_priority( holder, holder->real_priority, TRUE );
108      }
109      break;
110  }
111
112
113  if ( ( the_thread = _Thread_queue_Dequeue( &the_mutex->Wait_queue ) ) ) {
114
115#if defined(RTEMS_MULTIPROCESSING)
116    if ( !_Objects_Is_local_id( the_thread->Object.id ) ) {
117     
118      the_mutex->holder     = NULL;
119      the_mutex->holder_id  = the_thread->Object.id;
120      the_mutex->nest_count = 1;
121
122      ( *api_mutex_mp_support)( the_thread, id );
123
124    } else 
125#endif
126    {
127
128      the_mutex->holder     = the_thread;
129      the_mutex->holder_id  = the_thread->Object.id;
130      the_thread->resource_count++;
131      the_mutex->nest_count = 1;
132
133     /*
134      *  No special action for priority inheritance or priority ceiling
135      *  because the_thread is guaranteed to be the highest priority
136      *  thread waiting for the mutex.
137      */
138    }
139  } else
140    the_mutex->lock = CORE_MUTEX_UNLOCKED;
141
142  return( CORE_MUTEX_STATUS_SUCCESSFUL );
143}
144
Note: See TracBrowser for help on using the repository browser.