source: rtems/cpukit/posix/src/mutexsetprioceiling.c @ 5b6c290

5
Last change on this file since 5b6c290 was 5b6c290, checked in by Sebastian Huber <sebastian.huber@…>, on 12/01/16 at 19:42:48

score: Initialize thread queue context early

Initialize thread queue context early preferably outside the critical
section.

Remove implicit _Thread_queue_Context_initialize() from
_Thread_Wait_acquire().

  • Property mode set to 100644
File size: 2.4 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_no_protection( mutex );
53  _Assert( the_mutex != NULL );
54
55  if ( the_mutex->protocol == POSIX_MUTEX_PRIORITY_CEILING ) {
56    const Scheduler_Control *scheduler;
57    bool                     valid;
58    Priority_Control         new_priority;
59    Priority_Control         old_priority;
60
61    scheduler = _CORE_ceiling_mutex_Get_scheduler( &the_mutex->Mutex );
62    old_priority = _CORE_ceiling_mutex_Get_priority( &the_mutex->Mutex );
63    *old_ceiling = _POSIX_Priority_From_core( scheduler, old_priority );
64
65    new_priority = _POSIX_Priority_To_core( scheduler, prioceiling, &valid );
66    if ( valid ) {
67      Thread_queue_Context  queue_context;
68      Per_CPU_Control      *cpu_self;
69
70      _Thread_queue_Context_initialize( &queue_context );
71      _Thread_queue_Context_clear_priority_updates( &queue_context );
72      _CORE_ceiling_mutex_Set_priority(
73        &the_mutex->Mutex,
74        new_priority,
75        &queue_context
76      );
77      cpu_self = _Thread_Dispatch_disable();
78      _Thread_Priority_update( &queue_context );
79      _Thread_Dispatch_enable( cpu_self );
80      error = 0;
81    } else {
82      error = EINVAL;
83    }
84  } else {
85    *old_ceiling = 0;
86    error = 0;
87  }
88
89  unlock_error = pthread_mutex_unlock( mutex );
90  _Assert( unlock_error == 0 );
91  (void) unlock_error;
92  return error;
93}
Note: See TracBrowser for help on using the repository browser.