source: rtems/cpukit/posix/src/mutexsetprioceiling.c @ b8bdced1

5
Last change on this file since b8bdced1 was b8bdced1, checked in by Sebastian Huber <sebastian.huber@…>, on Apr 18, 2016 at 3:21:43 PM

posix: Simplify _POSIX_Mutex_Get_interrupt_disable

Remove superfluous location parameter.

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