ChibiOS/RT Architecture - Reference Manual - Guides |
00001 /* 00002 ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010 Giovanni Di Sirio. 00003 00004 This file is part of ChibiOS/RT. 00005 00006 ChibiOS/RT is free software; you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation; either version 3 of the License, or 00009 (at your option) any later version. 00010 00011 ChibiOS/RT is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 GNU General Public License for more details. 00015 00016 You should have received a copy of the GNU General Public License 00017 along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 00019 --- 00020 00021 A special exception to the GPL can be applied should you wish to distribute 00022 a combined work that includes ChibiOS/RT, without being obliged to provide 00023 the source code for any proprietary components. See the file exception.txt 00024 for full details of how and when the exception can be applied. 00025 */ 00026 00027 /** 00028 * @file chlists.h 00029 * @brief Thread queues/lists macros and structures. 00030 * @note All the macros present in this module, while public, are not 00031 * an OS API and should not be directly used in the user applications 00032 * code. 00033 * 00034 * @addtogroup internals 00035 * @{ 00036 */ 00037 00038 #ifndef _CHLISTS_H_ 00039 #define _CHLISTS_H_ 00040 00041 typedef struct Thread Thread; 00042 00043 /** 00044 * @brief Threads queue initialization. 00045 */ 00046 #define queue_init(tqp) ((tqp)->p_next = (tqp)->p_prev = (Thread *)(tqp)); 00047 00048 /** 00049 * @brief Threads list initialization. 00050 */ 00051 #define list_init(tlp) ((tlp)->p_next = (Thread *)(tlp)) 00052 00053 /** 00054 * @brief Evaluates to @p TRUE if the specified threads queue or list is 00055 * empty. 00056 */ 00057 #define isempty(p) ((p)->p_next == (Thread *)(p)) 00058 00059 /** 00060 * @brief Evaluates to @p TRUE if the specified threads queue or list is 00061 * not empty. 00062 */ 00063 #define notempty(p) ((p)->p_next != (Thread *)(p)) 00064 00065 /** 00066 * @brief Data part of a static threads queue initializer. 00067 * @details This macro should be used when statically initializing a threads 00068 * queue that is part of a bigger structure. 00069 * 00070 * @param[in] name the name of the threads queue variable 00071 */ 00072 #define _THREADSQUEUE_DATA(name) {(Thread *)&name, (Thread *)&name} 00073 00074 /** 00075 * @brief Static threads queue initializer. 00076 * @details Statically initialized threads queues require no explicit 00077 * initialization using @p queue_init(). 00078 * 00079 * @param[in] name the name of the threads queue variable 00080 */ 00081 #define THREADSQUEUE_DECL(name) ThreadsQueue name = _THREADSQUEUE_DATA(name) 00082 00083 /** 00084 * @extends ThreadsList 00085 * 00086 * @brief Generic threads bidirectional linked list header and element. 00087 */ 00088 typedef struct { 00089 Thread *p_next; /**< First @p Thread in the queue, or 00090 @p ThreadQueue when empty. */ 00091 Thread *p_prev; /**< Last @p Thread in the queue, or 00092 @p ThreadQueue when empty. */ 00093 } ThreadsQueue; 00094 00095 /** 00096 * @brief Generic threads single link list, it works like a stack. 00097 */ 00098 typedef struct { 00099 00100 Thread *p_next; /**< Last pushed @p Thread on the stack 00101 list, or pointer to itself if 00102 empty. */ 00103 } ThreadsList; 00104 00105 #if !CH_OPTIMIZE_SPEED 00106 00107 #ifdef __cplusplus 00108 extern "C" { 00109 #endif 00110 void prio_insert(Thread *tp, ThreadsQueue *tqp); 00111 void queue_insert(Thread *tp, ThreadsQueue *tqp); 00112 Thread *fifo_remove(ThreadsQueue *tqp); 00113 Thread *lifo_remove(ThreadsQueue *tqp); 00114 Thread *dequeue(Thread *tp); 00115 void list_insert(Thread *tp, ThreadsList *tlp); 00116 Thread *list_remove(ThreadsList *tlp); 00117 #ifdef __cplusplus 00118 } 00119 #endif 00120 00121 #endif /* !CH_OPTIMIZE_SPEED */ 00122 00123 #endif /* _CHLISTS_H_ */ 00124 00125 /** @} */