Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RTEMSScoreSchedulerSimple
0007  *
0008  * @brief This header file provides interfaces of the
0009  *   @ref RTEMSScoreSchedulerSimple which are only used by the implementation.
0010  */
0011 
0012 /*
0013  *  Copyright (C) 2011 On-Line Applications Research Corporation (OAR).
0014  *
0015  * Redistribution and use in source and binary forms, with or without
0016  * modification, are permitted provided that the following conditions
0017  * are met:
0018  * 1. Redistributions of source code must retain the above copyright
0019  *    notice, this list of conditions and the following disclaimer.
0020  * 2. Redistributions in binary form must reproduce the above copyright
0021  *    notice, this list of conditions and the following disclaimer in the
0022  *    documentation and/or other materials provided with the distribution.
0023  *
0024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0027  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0028  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0029  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0030  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0031  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0032  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0033  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0034  * POSSIBILITY OF SUCH DAMAGE.
0035  */
0036 
0037 #ifndef _RTEMS_SCORE_SCHEDULERSIMPLEIMPL_H
0038 #define _RTEMS_SCORE_SCHEDULERSIMPLEIMPL_H
0039 
0040 #include <rtems/score/schedulersimple.h>
0041 #include <rtems/score/chainimpl.h>
0042 #include <rtems/score/scheduleruniimpl.h>
0043 
0044 #ifdef __cplusplus
0045 extern "C" {
0046 #endif
0047 
0048 /**
0049  * @addtogroup RTEMSScoreSchedulerSimple
0050  *
0051  * @{
0052  */
0053 
0054 /**
0055  * @brief Gets context of the scheduler.
0056  *
0057  * @param scheduler The scheduler instance to get the context of.
0058  *
0059  * @return The context of @a scheduler.
0060  */
0061 static inline Scheduler_simple_Context *
0062   _Scheduler_simple_Get_context( const Scheduler_Control *scheduler )
0063 {
0064   return (Scheduler_simple_Context *) _Scheduler_Get_context( scheduler );
0065 }
0066 
0067 /**
0068  * @brief Checks if the priority is less or equal than the priority of the node.
0069  *
0070  * @param key is the priority to compare.
0071  *
0072  * @param to_insert is the chain node to insert.
0073  *
0074  * @param next is the chain node to compare the priority of.
0075  *
0076  * @retval true @a to_insert is smaller or equal than the priority of @a next.
0077  * @retval false @a to_insert is greater than the priority of @a next.
0078  */
0079 static inline bool _Scheduler_simple_Priority_less_equal(
0080   const void       *key,
0081   const Chain_Node *to_insert,
0082   const Chain_Node *next
0083 )
0084 {
0085   const unsigned int   *priority_to_insert;
0086   const Thread_Control *thread_next;
0087 
0088   (void) to_insert;
0089   priority_to_insert = (const unsigned int *) key;
0090   thread_next = (const Thread_Control *) next;
0091 
0092   return *priority_to_insert <= _Thread_Get_priority( thread_next );
0093 }
0094 
0095 /**
0096  * @brief Inserts the thread control with the given priority into the chain.
0097  *
0098  * @param[in, out] chain The chain to insert @a to_insert in.
0099  * @param[in, out] to_insert The node to insert into @a chain.
0100  * @param insert_priority The priority to insert @a to_insert with.
0101  */
0102 static inline void _Scheduler_simple_Insert(
0103   Chain_Control  *chain,
0104   Thread_Control *to_insert,
0105   unsigned int    insert_priority
0106 )
0107 {
0108   _Chain_Insert_ordered_unprotected(
0109     chain,
0110     &to_insert->Object.Node,
0111     &insert_priority,
0112     _Scheduler_simple_Priority_less_equal
0113   );
0114 }
0115 
0116 /**
0117  * @brief Extracts the threads node.
0118  *
0119  * @param scheduler This parameter is unused.
0120  * @param[in, out] the_thread The thread of which to extract the node out of its chain.
0121  * @param node This parameter is unused.
0122  */
0123 static inline void _Scheduler_simple_Extract(
0124   const Scheduler_Control *scheduler,
0125   Thread_Control          *the_thread,
0126   Scheduler_Node          *node
0127 )
0128 {
0129   (void) scheduler;
0130   (void) node;
0131 
0132   _Chain_Extract_unprotected( &the_thread->Object.Node );
0133 }
0134 
0135 /**
0136  * @brief Gets the highest priority ready thread of the scheduler.
0137  *
0138  * @param scheduler is the scheduler.
0139  */
0140 static inline Thread_Control *_Scheduler_simple_Get_highest_ready(
0141   const Scheduler_Control *scheduler
0142 )
0143 {
0144   Scheduler_simple_Context *context =
0145     _Scheduler_simple_Get_context( scheduler );
0146 
0147   return (Thread_Control *) _Chain_First( &context->Ready );
0148 }
0149 
0150 /** @} */
0151 
0152 #ifdef __cplusplus
0153 }
0154 #endif
0155 
0156 #endif
0157 /* end of include file */