summaryrefslogtreecommitdiffstats
path: root/spec/rtems/sem/if/set-priority.yml
blob: 5b76bd7475008b856682e067ca8ca5460127fb67 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
SPDX-License-Identifier: CC-BY-SA-4.0 OR BSD-2-Clause
brief: |
  Sets the priority by scheduler for the semaphore.
copyrights:
- Copyright (C) 2021 embedded brains GmbH (http://www.embedded-brains.de)
- Copyright (C) 1988, 2008 On-Line Applications Research Corporation (OAR)
definition:
  default:
    attributes: null
    body: null
    params:
    - ${../../type/if/id:/name} ${.:/params[0]/name}
    - ${../../type/if/id:/name} ${.:/params[1]/name}
    - ${../../type/if/priority:/name} ${.:/params[2]/name}
    - ${../../type/if/priority:/name} *${.:/params[3]/name}
    return: ${../../status/if/code:/name}
  variants: []
description: |
  This directive sets the priority of the semaphore specified by
  ${.:/params[0]/name}.  The priority corresponds to the scheduler specified by
  ${.:/params[1]/name}.

  The special priority value ${../../task/if/current-priority:/name} can be
  used to get the current priority without changing it.

  The availability and use of a priority depends on the class and locking
  protocol of the semaphore:

  * For local, binary semaphores using the MrsP locking protocol, the ceiling
    priority for each scheduler can be set by this directive.

  * For local, binary semaphores using the priority ceiling protocol, the
    ceiling priority can be set by this directive.

  * For other semaphore classes and locking protocols, setting a priority is
    undefined behaviour.
enabled-by: true
index-entries:
- set priority by scheduler for a semaphore
interface-type: function
links:
- role: interface-placement
  uid: header
- role: interface-ingroup
  uid: group
- role: constraint
  uid: /constraint/directive-ctx-isr
- role: constraint
  uid: /constraint/directive-ctx-devinit
- role: constraint
  uid: /constraint/directive-ctx-task
- role: constraint
  uid: /constraint/priority-may-preempt
name: rtems_semaphore_set_priority
notes: |
  Please have a look at the following example:

  .. code-block:: c
      :linenos:

      #include <assert.h>
      #include <rtems.h>

      #define SCHED_A rtems_build_name( ' ', ' ', ' ', 'A' )
      #define SCHED_B rtems_build_name( ' ', ' ', ' ', 'B' )

      static void Init( rtems_task_argument arg )
      {
        rtems_status_code   sc;
        rtems_id            semaphore_id;
        rtems_id            scheduler_a_id;
        rtems_id            scheduler_b_id;
        rtems_task_priority prio;

        (void) arg;

        // Get the scheduler identifiers
        sc = rtems_scheduler_ident( SCHED_A, &scheduler_a_id );
        assert( sc == RTEMS_SUCCESSFUL );
        sc = rtems_scheduler_ident( SCHED_B, &scheduler_b_id );
        assert( sc == RTEMS_SUCCESSFUL );

        // Create a local, binary semaphore using the MrsP locking protocol
        sc = rtems_semaphore_create(
          rtems_build_name( 'M', 'R', 'S', 'P' ),
          1,
          RTEMS_BINARY_SEMAPHORE | RTEMS_MULTIPROCESSOR_RESOURCE_SHARING,
          1,
          &semaphore_id
        );
        assert( sc == RTEMS_SUCCESSFUL );

        // The ceiling priority for each scheduler is equal to the priority
        // specified for the semaphore creation.
        prio = RTEMS_CURRENT_PRIORITY;
        sc = rtems_semaphore_set_priority( semaphore_id, scheduler_a_id, prio, &prio );
        assert( sc == RTEMS_SUCCESSFUL );
        assert( prio == 1 );

        // Check the old value and set a new ceiling priority for scheduler B
        prio = 2;
        sc = rtems_semaphore_set_priority( semaphore_id, scheduler_b_id, prio, &prio );
        assert( sc == RTEMS_SUCCESSFUL );
        assert( prio == 1 );

        // Check the ceiling priority values
        prio = RTEMS_CURRENT_PRIORITY;
        sc = rtems_semaphore_set_priority( semaphore_id, scheduler_a_id, prio, &prio );
        assert( sc == RTEMS_SUCCESSFUL );
        assert( prio == 1 );
        prio = RTEMS_CURRENT_PRIORITY;
        sc = rtems_semaphore_set_priority( semaphore_id, scheduler_b_id, prio, &prio );
        assert( sc == RTEMS_SUCCESSFUL );
        assert( prio == 2 );

        sc = rtems_semaphore_delete( semaphore_id );
        assert( sc == RTEMS_SUCCESSFUL );

        rtems_shutdown_executive( 0 );
      }

      #define CONFIGURE_APPLICATION_NEEDS_CLOCK_DRIVER
      #define CONFIGURE_APPLICATION_NEEDS_CONSOLE_DRIVER
      #define CONFIGURE_MAXIMUM_TASKS 1
      #define CONFIGURE_MAXIMUM_SEMAPHORES 1
      #define CONFIGURE_MAXIMUM_PROCESSORS 2

      #define CONFIGURE_SCHEDULER_SIMPLE_SMP

      #include <rtems/scheduler.h>

      RTEMS_SCHEDULER_CONTEXT_SIMPLE_SMP( a );
      RTEMS_SCHEDULER_CONTEXT_SIMPLE_SMP( b );

      #define CONFIGURE_SCHEDULER_TABLE_ENTRIES \
          RTEMS_SCHEDULER_TABLE_SIMPLE_SMP( a, SCHED_A ), \
          RTEMS_SCHEDULER_TABLE_SIMPLE_SMP( b, SCHED_B )

      #define CONFIGURE_SCHEDULER_ASSIGNMENTS \
          RTEMS_SCHEDULER_ASSIGN( 0, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_MANDATORY ), \
          RTEMS_SCHEDULER_ASSIGN( 1, RTEMS_SCHEDULER_ASSIGN_PROCESSOR_MANDATORY )

      #define CONFIGURE_RTEMS_INIT_TASKS_TABLE
      #define CONFIGURE_INIT

      #include <rtems/confdefs.h>
params:
- description: |
    is the semaphore identifier.
  dir: null
  name: semaphore_id
- description: |
    is the identifier of the scheduler corresponding to the new priority.
  dir: null
  name: scheduler_id
- description: |
    is the new priority corresponding to the specified scheduler.
  dir: null
  name: new_priority
- description: |
    is the pointer to a task priority variable.  When the directive call is
    successful, the old priority of the semaphore corresponding to the
    specified scheduler will be stored in this variable.
  dir: out
  name: old_priority
return:
  return: null
  return-values:
  - description: |
      The requested operation was successful.
    value: ${../../status/if/successful:/name}
  - description: |
      The ${.:/params[3]/name} parameter was ${/c/if/null:/name}.
    value: ${../../status/if/invalid-address:/name}
  - description: |
      There was no scheduler associated with the identifier specified by
      ${.:/params[1]/name}.
    value: ${../../status/if/invalid-id:/name}
  - description: |
      There was no semaphore associated with the identifier specified by
      ${.:/params[0]/name}.
    value: ${../../status/if/invalid-id:/name}
  - description: |
      The semaphore resided on a remote node.
    value: ${../../status/if/illegal-on-remote-object:/name}
  - description: |
      The ${.:/params[2]/name} parameter was invalid.
    value: ${../../status/if/invalid-priority:/name}
  - description: |
      Setting a priority for the class or locking protocol of the semaphore is
      undefined behaviour.
    value: ${../../status/if/not-defined:/name}
type: interface