source: rtems/cpukit/posix/src/mutexsetprioceiling.c @ 0e16fa45

5
Last change on this file since 0e16fa45 was de59c065, checked in by Sebastian Huber <sebastian.huber@…>, on 09/27/17 at 13:08:33

posix: Implement self-contained POSIX mutex

POSIX mutexes are now available in all configurations and no longer
depend on --enable-posix.

Update #2514.
Update #3112.

  • Property mode set to 100644
File size: 2.3 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  int                  error;
36  int                  unlock_error;
37
38  if ( old_ceiling == NULL ) {
39    return EINVAL;
40  }
41
42  /*
43   *  Must acquire the mutex before we can change it's ceiling.
44   *  POSIX says block until we acquire it.
45   */
46  error = pthread_mutex_lock( mutex );
47  if ( error != 0 ) {
48    _Assert( error == EINVAL );
49    return EINVAL;
50  }
51
52  the_mutex = _POSIX_Mutex_Get( mutex );
53
54  if (
55    _POSIX_Mutex_Get_protocol( the_mutex->flags )
56      == POSIX_MUTEX_PRIORITY_CEILING
57  ) {
58    const Scheduler_Control *scheduler;
59    bool                     valid;
60    Priority_Control         new_priority;
61    Priority_Control         old_priority;
62
63    scheduler = _POSIX_Mutex_Get_scheduler( the_mutex );
64    old_priority = _POSIX_Mutex_Get_priority( the_mutex );
65    *old_ceiling = _POSIX_Priority_From_core( scheduler, old_priority );
66
67    new_priority = _POSIX_Priority_To_core( scheduler, prioceiling, &valid );
68    if ( valid ) {
69      Thread_queue_Context  queue_context;
70      Per_CPU_Control      *cpu_self;
71
72      _Thread_queue_Context_initialize( &queue_context );
73      _Thread_queue_Context_clear_priority_updates( &queue_context );
74      _POSIX_Mutex_Set_priority(
75        the_mutex,
76        new_priority,
77        &queue_context
78      );
79      cpu_self = _Thread_Dispatch_disable();
80      _Thread_Priority_update( &queue_context );
81      _Thread_Dispatch_enable( cpu_self );
82      error = 0;
83    } else {
84      error = EINVAL;
85    }
86  } else {
87    *old_ceiling = 0;
88    error = 0;
89  }
90
91  unlock_error = pthread_mutex_unlock( mutex );
92  _Assert( unlock_error == 0 );
93  (void) unlock_error;
94  return error;
95}
Note: See TracBrowser for help on using the repository browser.