source: rtems/cpukit/posix/src/mutexsetprioceiling.c @ 48b04fc3

5
Last change on this file since 48b04fc3 was 48b04fc3, checked in by Sebastian Huber <sebastian.huber@…>, on Apr 19, 2016 at 4:28:03 AM

posix: Avoid Giant lock for mutexes

Delete _POSIX_Mutex_Get(). Use _POSIX_Mutex_Get_interrupt_disable()
instead.

Update #2555.

  • Property mode set to 100644
File size: 1.9 KB
Line 
1/**
2 * @file
3 *
4 * @brief Changes the Priority Ceiling of a Mutex and Releases it
5 * @ingroup POSIXAPI
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2009.
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.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/posix/muteximpl.h>
22#include <rtems/posix/priorityimpl.h>
23
24/*
25 *  13.6.2 Change the Priority Ceiling of a Mutex, P1003.1c/Draft 10, p. 131
26 */
27
28int pthread_mutex_setprioceiling(
29  pthread_mutex_t   *mutex,
30  int                prioceiling,
31  int               *old_ceiling
32)
33{
34  register POSIX_Mutex_Control *the_mutex;
35  Priority_Control              the_priority;
36  ISR_lock_Context              lock_context;
37
38  if ( !old_ceiling )
39    return EINVAL;
40
41  if ( !_POSIX_Priority_Is_valid( prioceiling ) )
42    return EINVAL;
43
44  the_priority = _POSIX_Priority_To_core( prioceiling );
45
46  /*
47   *  Must acquire the mutex before we can change it's ceiling.
48   *  POSIX says block until we acquire it.
49   */
50  (void) pthread_mutex_lock( mutex );
51
52  /*
53   *  Do not worry about the return code from this.  The Get operation
54   *  will also fail if it is a bad id or was deleted between the two
55   *  operations.
56   *
57   *  NOTE: This makes it easier to get 100% binary coverage since the
58   *        bad Id case is handled by the switch.
59   */
60  the_mutex = _POSIX_Mutex_Get_interrupt_disable( mutex, &lock_context );
61
62  if ( the_mutex == NULL ) {
63    return EINVAL;
64  }
65
66  *old_ceiling = _POSIX_Priority_From_core(
67    the_mutex->Mutex.Attributes.priority_ceiling
68  );
69  the_mutex->Mutex.Attributes.priority_ceiling = the_priority;
70
71  /*
72   *  We are required to unlock the mutex before we return.
73   */
74  _CORE_mutex_Surrender(
75    &the_mutex->Mutex,
76    NULL,
77    0,
78    &lock_context
79  );
80  return 0;
81}
Note: See TracBrowser for help on using the repository browser.