source: rtems/cpukit/posix/src/mutexsetprioceiling.c @ 06f5ec9

4.104.115
Last change on this file since 06f5ec9 was 06f5ec9, checked in by Joel Sherrill <joel.sherrill@…>, on 07/07/09 at 17:29:47

2009-07-07 Joel Sherrill <joel.sherrill@…>

  • posix/src/mutexsetprioceiling.c: Restructure to eliminate code paths which are unreachable. Also add more comments.
  • score/src/coremutexsurrender.c: Mark some code as RTEMS_DEBUG only since it cannot be hit unless coremutexseize.c is broken.
  • Property mode set to 100644
File size: 2.2 KB
Line 
1/*
2 *  COPYRIGHT (c) 1989-2007.
3 *  On-Line Applications Research Corporation (OAR).
4 *
5 *  The license and distribution terms for this file may be
6 *  found in the file LICENSE in this distribution or at
7 *  http://www.rtems.com/license/LICENSE.
8 *
9 *  $Id$
10 */
11
12#if HAVE_CONFIG_H
13#include "config.h"
14#endif
15
16#include <errno.h>
17#include <pthread.h>
18
19#include <rtems/system.h>
20#include <rtems/score/coremutex.h>
21#include <rtems/score/watchdog.h>
22#include <rtems/posix/mutex.h>
23#include <rtems/posix/priority.h>
24#include <rtems/posix/time.h>
25
26/*PAGE
27 *
28 *  13.6.2 Change the Priority Ceiling of a Mutex, P1003.1c/Draft 10, p. 131
29 */
30
31int pthread_mutex_setprioceiling(
32  pthread_mutex_t   *mutex,
33  int                prioceiling,
34  int               *old_ceiling
35)
36{
37  register POSIX_Mutex_Control *the_mutex;
38  Objects_Locations             location;
39  Priority_Control              the_priority;
40  int                           status;
41
42  if ( !old_ceiling )
43    return EINVAL;
44
45  if ( !_POSIX_Priority_Is_valid( prioceiling ) )
46    return EINVAL;
47
48  the_priority = _POSIX_Priority_To_core( prioceiling );
49
50  /*
51   *  Must acquire the mutex before we can change it's ceiling.
52   *  POSIX says block until we acquire it.
53   */
54  (void) pthread_mutex_lock( mutex );
55
56  /*
57   *  Do not worry about the return code from this.  The Get operation
58   *  will also fail if it is a bad id or was deleted between the two
59   *  operations.
60   *
61   *  NOTE: This makes it easier to get 100% binary coverage since the
62   *        bad Id case is handled by the switch.
63   */
64  the_mutex = _POSIX_Mutex_Get( mutex, &location );
65  switch ( location ) {
66
67    case OBJECTS_LOCAL:
68      *old_ceiling = _POSIX_Priority_From_core(
69        the_mutex->Mutex.Attributes.priority_ceiling
70      );
71      the_mutex->Mutex.Attributes.priority_ceiling = the_priority;
72      /*
73       *  We are required to unlock the mutex before we return.
74       */
75      _CORE_mutex_Surrender(
76        &the_mutex->Mutex,
77        the_mutex->Object.id,
78        NULL
79      );
80      _Thread_Enable_dispatch();
81
82      return 0;
83
84#if defined(RTEMS_MULTIPROCESSING)
85    case OBJECTS_REMOTE:  /* impossible to get here */
86#endif
87    case OBJECTS_ERROR:
88      break;
89  }
90
91  return EINVAL;
92}
Note: See TracBrowser for help on using the repository browser.