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 #include #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_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 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