source: rtems/cpukit/rtems/src/semsetpriority.c @ 3692095

Last change on this file since 3692095 was 3692095, checked in by Sebastian Huber <sebastian.huber@…>, on May 30, 2016 at 8:41:22 AM

rtems: Move MrsP semaphore operations

Move MrsP semaphore operations to a less prominent location. Fix field
name.

  • Property mode set to 100644
File size: 3.5 KB
Line 
1/*
2 * Copyright (c) 2014 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#if HAVE_CONFIG_H
16  #include "config.h"
17#endif
18
19#include <rtems/rtems/semimpl.h>
20#include <rtems/rtems/tasksimpl.h>
21#include <rtems/score/schedulerimpl.h>
22
23static rtems_status_code _Semaphore_Set_priority(
24  Semaphore_Control    *the_semaphore,
25  rtems_id              scheduler_id,
26  rtems_task_priority   new_priority,
27  rtems_task_priority  *old_priority_p,
28  Thread_queue_Context *queue_context
29)
30{
31  rtems_status_code    sc;
32  rtems_task_priority  old_priority;
33#if defined(RTEMS_SMP)
34  MRSP_Control        *mrsp;
35  uint32_t             scheduler_index;
36#endif
37
38  new_priority = _RTEMS_tasks_Priority_to_Core( new_priority );
39
40  switch ( the_semaphore->variant ) {
41    case SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING:
42      _CORE_mutex_Acquire_critical(
43        &the_semaphore->Core_control.Mutex.Recursive.Mutex,
44        queue_context
45      );
46
47      old_priority = the_semaphore->Core_control.Mutex.priority_ceiling;
48
49      if ( new_priority != RTEMS_CURRENT_PRIORITY ) {
50        the_semaphore->Core_control.Mutex.priority_ceiling = new_priority;
51      }
52
53      _CORE_mutex_Release(
54        &the_semaphore->Core_control.Mutex.Recursive.Mutex,
55        queue_context
56      );
57      sc = RTEMS_SUCCESSFUL;
58      break;
59#if defined(RTEMS_SMP)
60    case SEMAPHORE_VARIANT_MRSP:
61      mrsp = &the_semaphore->Core_control.MRSP;
62      scheduler_index = _Scheduler_Get_index_by_id( scheduler_id );
63
64      _MRSP_Acquire_critical( mrsp, queue_context );
65
66      old_priority = _MRSP_Get_ceiling_priority( mrsp, scheduler_index );
67
68      if ( new_priority != RTEMS_CURRENT_PRIORITY ) {
69        _MRSP_Set_ceiling_priority( mrsp, scheduler_index, new_priority );
70      }
71
72      _MRSP_Release( mrsp, queue_context );
73      sc = RTEMS_SUCCESSFUL;
74      break;
75#endif
76    default:
77      _Assert(
78        the_semaphore->variant == SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY
79          || the_semaphore->variant == SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL
80          || the_semaphore->variant == SEMAPHORE_VARIANT_SIMPLE_BINARY
81          || the_semaphore->variant == SEMAPHORE_VARIANT_COUNTING
82      );
83      _ISR_lock_ISR_enable( &queue_context->Lock_context );
84      old_priority = 0;
85      sc = RTEMS_NOT_DEFINED;
86      break;
87  }
88
89  *old_priority_p = _RTEMS_tasks_Priority_from_Core( old_priority );
90
91  return sc;
92}
93
94rtems_status_code rtems_semaphore_set_priority(
95  rtems_id             semaphore_id,
96  rtems_id             scheduler_id,
97  rtems_task_priority  new_priority,
98  rtems_task_priority *old_priority
99)
100{
101  Semaphore_Control    *the_semaphore;
102  Thread_queue_Context  queue_context;
103
104  if ( new_priority != RTEMS_CURRENT_PRIORITY &&
105       !_RTEMS_tasks_Priority_is_valid( new_priority ) ) {
106    return RTEMS_INVALID_PRIORITY;
107  }
108
109  if ( old_priority == NULL ) {
110    return RTEMS_INVALID_ADDRESS;
111  }
112
113  if ( !_Scheduler_Is_id_valid( scheduler_id ) ) {
114    return RTEMS_INVALID_ID;
115  }
116
117  the_semaphore = _Semaphore_Get( semaphore_id, &queue_context );
118
119  if ( the_semaphore == NULL ) {
120#if defined(RTEMS_MULTIPROCESSING)
121    if ( _Semaphore_MP_Is_remote( semaphore_id ) ) {
122      return RTEMS_ILLEGAL_ON_REMOTE_OBJECT;
123    }
124#endif
125
126    return RTEMS_INVALID_ID;
127  }
128
129  return _Semaphore_Set_priority(
130    the_semaphore,
131    scheduler_id,
132    new_priority,
133    old_priority,
134    &queue_context
135  );
136}
Note: See TracBrowser for help on using the repository browser.