source: rtems/cpukit/posix/src/mutexsetprioceiling.c @ 1a4eac50

5
Last change on this file since 1a4eac50 was 1a4eac50, checked in by Sebastian Huber <sebastian.huber@…>, on 06/15/16 at 14:31:33

posix: Generalize _POSIX_Priority_To_core()

Move POSIX API priority validation into _POSIX_Priority_To_core().

  • Property mode set to 100644
File size: 1.7 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  POSIX_Mutex_Control     *the_mutex;
35  const Scheduler_Control *scheduler;
36  bool                     valid;
37  Priority_Control         priority;
38  int                      error;
39  int                      unlock_error;
40
41  if ( !old_ceiling )
42    return EINVAL;
43
44  /*
45   *  Must acquire the mutex before we can change it's ceiling.
46   *  POSIX says block until we acquire it.
47   */
48  error = pthread_mutex_lock( mutex );
49  if ( error != 0 ) {
50    _Assert( error == EINVAL );
51    return EINVAL;
52  }
53
54  the_mutex = _POSIX_Mutex_Get_no_protection( mutex );
55  _Assert( the_mutex != NULL );
56
57  scheduler = &_Scheduler_Table[ 0 ];
58
59  *old_ceiling = _POSIX_Priority_From_core(
60    scheduler,
61    the_mutex->Mutex.priority_ceiling
62  );
63
64  priority = _POSIX_Priority_To_core( scheduler, prioceiling, &valid );
65  if ( valid ) {
66    the_mutex->Mutex.priority_ceiling = priority;
67    error = 0;
68  } else {
69    error = EINVAL;
70  }
71
72  unlock_error = pthread_mutex_unlock( mutex );
73  _Assert( unlock_error == 0 );
74  (void) unlock_error;
75  return error;
76}
Note: See TracBrowser for help on using the repository browser.