source: rtems/cpukit/rtems/src/semsetpriority.c @ 6b5f22dc

Last change on this file since 6b5f22dc was 6b5f22dc, checked in by Sebastian Huber <sebastian.huber@…>, on 11/26/20 at 10:45:47

rtems: Canonicalize Doxygen @file comments

Use common phrases for the file brief descriptions.

Update #3706.

  • Property mode set to 100644
File size: 4.3 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup RTEMSImplClassicSemaphore
5 *
6 * @brief This source file contains the implementation of
7 *   rtems_semaphore_set_priority().
8 */
9
10/*
11 * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
12 *
13 *  embedded brains GmbH
14 *  Dornierstr. 4
15 *  82178 Puchheim
16 *  Germany
17 *  <rtems@embedded-brains.de>
18 *
19 * The license and distribution terms for this file may be
20 * found in the file LICENSE in this distribution or at
21 * http://www.rtems.org/license/LICENSE.
22 */
23
24#ifdef HAVE_CONFIG_H
25#include "config.h"
26#endif
27
28#include <rtems/rtems/semimpl.h>
29#include <rtems/rtems/tasksimpl.h>
30#include <rtems/score/schedulerimpl.h>
31
32static rtems_status_code _Semaphore_Is_scheduler_valid(
33  const CORE_ceiling_mutex_Control *the_mutex,
34  const Scheduler_Control          *scheduler
35)
36{
37#if defined(RTEMS_SMP)
38  if ( scheduler != _CORE_ceiling_mutex_Get_scheduler( the_mutex ) ) {
39    return RTEMS_NOT_DEFINED;
40  }
41#endif
42
43  return RTEMS_SUCCESSFUL;
44}
45
46static rtems_status_code _Semaphore_Set_priority(
47  Semaphore_Control       *the_semaphore,
48  const Scheduler_Control *scheduler,
49  rtems_task_priority      new_priority,
50  rtems_task_priority     *old_priority_p,
51  Thread_queue_Context    *queue_context
52)
53{
54  rtems_status_code  sc;
55  bool               valid;
56  Priority_Control   core_priority;
57  Priority_Control   old_priority;
58  Per_CPU_Control   *cpu_self;
59  Semaphore_Variant  variant;
60
61  core_priority = _RTEMS_Priority_To_core( scheduler, new_priority, &valid );
62  if ( new_priority != RTEMS_CURRENT_PRIORITY && !valid ) {
63    _ISR_lock_ISR_enable( &queue_context->Lock_context.Lock_context );
64    return RTEMS_INVALID_PRIORITY;
65  }
66
67  _Thread_queue_Context_clear_priority_updates( queue_context );
68  _Thread_queue_Acquire_critical(
69    &the_semaphore->Core_control.Wait_queue,
70    queue_context
71  );
72  variant = _Semaphore_Get_variant( _Semaphore_Get_flags( the_semaphore ) );
73
74  switch ( variant ) {
75    case SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING:
76      sc = _Semaphore_Is_scheduler_valid(
77        &the_semaphore->Core_control.Mutex,
78        scheduler
79      );
80
81      old_priority = _CORE_ceiling_mutex_Get_priority(
82        &the_semaphore->Core_control.Mutex
83      );
84
85      if ( sc == RTEMS_SUCCESSFUL && new_priority != RTEMS_CURRENT_PRIORITY ) {
86        _CORE_ceiling_mutex_Set_priority(
87          &the_semaphore->Core_control.Mutex,
88          core_priority,
89          queue_context
90        );
91      }
92
93      break;
94#if defined(RTEMS_SMP)
95    case SEMAPHORE_VARIANT_MRSP:
96      old_priority = _MRSP_Get_priority(
97        &the_semaphore->Core_control.MRSP,
98        scheduler
99      );
100
101      if ( new_priority != RTEMS_CURRENT_PRIORITY ) {
102        _MRSP_Set_priority(
103          &the_semaphore->Core_control.MRSP,
104          scheduler,
105          core_priority
106        );
107      }
108
109      sc = RTEMS_SUCCESSFUL;
110      break;
111#endif
112    default:
113      _Assert(
114        variant == SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY
115          || variant == SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL
116          || variant == SEMAPHORE_VARIANT_SIMPLE_BINARY
117          || variant == SEMAPHORE_VARIANT_COUNTING
118      );
119      old_priority = 0;
120      sc = RTEMS_NOT_DEFINED;
121      break;
122  }
123
124  cpu_self = _Thread_queue_Dispatch_disable( queue_context );
125  _Thread_queue_Release(
126    &the_semaphore->Core_control.Wait_queue,
127    queue_context
128  );
129  _Thread_Priority_update( queue_context );
130  _Thread_Dispatch_enable( cpu_self );
131
132  *old_priority_p = _RTEMS_Priority_From_core( scheduler, old_priority );
133  return sc;
134}
135
136rtems_status_code rtems_semaphore_set_priority(
137  rtems_id             semaphore_id,
138  rtems_id             scheduler_id,
139  rtems_task_priority  new_priority,
140  rtems_task_priority *old_priority
141)
142{
143  const Scheduler_Control *scheduler;
144  Semaphore_Control       *the_semaphore;
145  Thread_queue_Context     queue_context;
146
147  if ( old_priority == NULL ) {
148    return RTEMS_INVALID_ADDRESS;
149  }
150
151  scheduler = _Scheduler_Get_by_id( scheduler_id );
152  if ( scheduler == NULL ) {
153    return RTEMS_INVALID_ID;
154  }
155
156  the_semaphore = _Semaphore_Get( semaphore_id, &queue_context );
157
158  if ( the_semaphore == NULL ) {
159#if defined(RTEMS_MULTIPROCESSING)
160    if ( _Semaphore_MP_Is_remote( semaphore_id ) ) {
161      return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
162    }
163#endif
164
165    return RTEMS_INVALID_ID;
166  }
167
168  return _Semaphore_Set_priority(
169    the_semaphore,
170    scheduler,
171    new_priority,
172    old_priority,
173    &queue_context
174  );
175}
Note: See TracBrowser for help on using the repository browser.