Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:44

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /*
0004  *  COPYRIGHT (c) 1989-2011.
0005  *  On-Line Applications Research Corporation (OAR).
0006  *
0007  * Redistribution and use in source and binary forms, with or without
0008  * modification, are permitted provided that the following conditions
0009  * are met:
0010  * 1. Redistributions of source code must retain the above copyright
0011  *    notice, this list of conditions and the following disclaimer.
0012  * 2. Redistributions in binary form must reproduce the above copyright
0013  *    notice, this list of conditions and the following disclaimer in the
0014  *    documentation and/or other materials provided with the distribution.
0015  *
0016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0026  * POSSIBILITY OF SUCH DAMAGE.
0027  */
0028 
0029 #ifdef HAVE_CONFIG_H
0030 #include "config.h"
0031 #endif
0032 
0033 #include "system.h"
0034 
0035 rtems_task Priority_task(
0036   rtems_task_argument its_index_arg
0037 )
0038 {
0039   rtems_interval      timeout;
0040   rtems_task_priority its_priority;
0041   rtems_task_priority current_priority;
0042   rtems_status_code   status;
0043   int                 its_index;
0044   uint32_t            index;
0045 
0046   its_index = (int) its_index_arg;
0047   its_priority = Task_priority[ its_index ];
0048 
0049   if ( its_priority < 3 )
0050     timeout = 5 * rtems_clock_get_ticks_per_second();
0051   else
0052     timeout = RTEMS_NO_TIMEOUT;
0053 
0054   put_name( Priority_task_name[ its_index ], FALSE );
0055   puts( " - rtems_semaphore_obtain - wait forever on SM2" );
0056 
0057   status = rtems_semaphore_obtain(
0058     Semaphore_id[ 2 ],
0059     RTEMS_DEFAULT_OPTIONS,
0060     timeout
0061   );
0062   directive_failed( status, "rtems_semaphore_obtain of SM2" );
0063 
0064   if ( its_priority < PRIORITY_INHERIT_BASE_PRIORITY ) {
0065     printf(
0066       "PRI%d - WHY AM I HERE? (pri=%" PRIdrtems_task_priority ")",
0067      its_index,
0068      its_priority
0069     );
0070     rtems_test_exit( 0 );
0071   }
0072 
0073   /* special case of setting priority while holding a resource */
0074   {
0075     rtems_task_priority priority;
0076     rtems_task_priority old_priority;
0077 
0078     puts( "Set priority of self while holding resource" );
0079     status =
0080       rtems_task_set_priority( RTEMS_SELF, RTEMS_CURRENT_PRIORITY, &priority );
0081     directive_failed( status, "rtems_task_set_priority get current" );
0082     status = rtems_task_set_priority( RTEMS_SELF, priority, &old_priority );
0083     directive_failed( status, "rtems_task_set_priority with resource" );
0084     if ( priority != old_priority ) {
0085       printf(
0086         "priority != old_priority (%" PRIdrtems_task_priority
0087             " != %" PRIdrtems_task_priority ")\n",
0088          priority,
0089          old_priority
0090       );
0091       rtems_test_exit(0);
0092     }
0093   }
0094 
0095   if ( its_index == 5 )
0096     puts( "PRI5 - rtems_task_suspend - until all priority tasks blocked" );
0097   status = rtems_task_suspend( RTEMS_SELF );
0098   directive_failed( status, "rtems_task_suspend" );
0099 
0100   puts( "PRI5 - rtems_task_delete - all tasks waiting on SM2" );
0101   for ( index = 1 ; index < 5 ; index++ ) {
0102     status = rtems_task_delete( Priority_task_id[ index ] );
0103     directive_failed( status, "rtems_task_delete loop" );
0104   }
0105 
0106   puts( "PRI5 - rtems_semaphore_obtain - nested" );
0107   status = rtems_semaphore_obtain(
0108     Semaphore_id[ 2 ],
0109     RTEMS_DEFAULT_OPTIONS,
0110     timeout
0111   );
0112   directive_failed( status, "rtems_semaphore_obtain nested" );
0113 
0114   puts( "PRI5 - rtems_semaphore_release - nested" );
0115   status = rtems_semaphore_release( Semaphore_id[ 2 ] );
0116   directive_failed( status, "rtems_semaphore_release nested " );
0117 
0118   puts( "PRI5 - rtems_semaphore_release - restore priority" );
0119   status = rtems_semaphore_release( Semaphore_id[ 2 ] );
0120   directive_failed( status, "rtems_semaphore_release" );
0121 
0122   status = rtems_task_set_priority(
0123     RTEMS_SELF,
0124     RTEMS_CURRENT_PRIORITY,
0125     &current_priority
0126   );
0127   directive_failed( status, "PRI5 rtems_task_set_priority CURRENT" );
0128   printf(
0129     "PRI5 - priority of PRI5 is %" PRIdrtems_task_priority "\n",
0130      current_priority
0131   );
0132 
0133   (void) rtems_task_suspend( RTEMS_SELF );
0134 }