ChibiOS/RT
2.5.1
chinline.h
Go to the documentation of this file.
00001 /*
00002     ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
00003                  2011,2012 Giovanni Di Sirio.
00004 
00005     This file is part of ChibiOS/RT.
00006 
00007     ChibiOS/RT is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 3 of the License, or
00010     (at your option) any later version.
00011 
00012     ChibiOS/RT is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015     GNU General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program.  If not, see <http://www.gnu.org/licenses/>.
00019 */
00020 
00021 /**
00022  * @file    chinline.h
00023  * @brief   Kernel inlined functions.
00024  * @details In this file there are a set of inlined functions if the
00025  *          @p CH_OPTIMIZE_SPEED is enabled.
00026  */
00027 
00028 #ifndef _CHINLINE_H_
00029 #define _CHINLINE_H_
00030 
00031 /* If the performance code path has been chosen then all the following
00032    functions are inlined into the various kernel modules.*/
00033 #if CH_OPTIMIZE_SPEED
00034 static INLINE void prio_insert(Thread *tp, ThreadsQueue *tqp) {
00035 
00036   Thread *cp = (Thread *)tqp;
00037   do {
00038     cp = cp->p_next;
00039   } while ((cp != (Thread *)tqp) && (cp->p_prio >= tp->p_prio));
00040   tp->p_next = cp;
00041   tp->p_prev = cp->p_prev;
00042   tp->p_prev->p_next = cp->p_prev = tp;
00043 }
00044 
00045 static INLINE void queue_insert(Thread *tp, ThreadsQueue *tqp) {
00046 
00047   tp->p_next = (Thread *)tqp;
00048   tp->p_prev = tqp->p_prev;
00049   tp->p_prev->p_next = tqp->p_prev = tp;
00050 }
00051 
00052 static INLINE Thread *fifo_remove(ThreadsQueue *tqp) {
00053   Thread *tp = tqp->p_next;
00054 
00055   (tqp->p_next = tp->p_next)->p_prev = (Thread *)tqp;
00056   return tp;
00057 }
00058 
00059 static INLINE Thread *lifo_remove(ThreadsQueue *tqp) {
00060   Thread *tp = tqp->p_prev;
00061 
00062   (tqp->p_prev = tp->p_prev)->p_next = (Thread *)tqp;
00063   return tp;
00064 }
00065 
00066 static INLINE Thread *dequeue(Thread *tp) {
00067 
00068   tp->p_prev->p_next = tp->p_next;
00069   tp->p_next->p_prev = tp->p_prev;
00070   return tp;
00071 }
00072 
00073 static INLINE void list_insert(Thread *tp, ThreadsList *tlp) {
00074 
00075   tp->p_next = tlp->p_next;
00076   tlp->p_next = tp;
00077 }
00078 
00079 static INLINE Thread *list_remove(ThreadsList *tlp) {
00080 
00081   Thread *tp = tlp->p_next;
00082   tlp->p_next = tp->p_next;
00083   return tp;
00084 }
00085 #endif /* CH_OPTIMIZE_SPEED */
00086 
00087 #endif /* _CHINLINE_H_ */