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 chmtx.h 00029 * @brief Mutexes macros and structures. 00030 * 00031 * @addtogroup mutexes 00032 * @{ 00033 */ 00034 00035 #ifndef _CHMTX_H_ 00036 #define _CHMTX_H_ 00037 00038 #if CH_USE_MUTEXES 00039 00040 /** 00041 * @brief Mutex structure. 00042 */ 00043 typedef struct Mutex { 00044 ThreadsQueue m_queue; /**< @brief Queue of the threads sleeping 00045 on this Mutex. */ 00046 Thread *m_owner; /**< @brief Owner @p Thread pointer or 00047 @p NULL. */ 00048 struct Mutex *m_next; /**< @brief Next @p Mutex into an 00049 owner-list or @p NULL. */ 00050 } Mutex; 00051 00052 #ifdef __cplusplus 00053 extern "C" { 00054 #endif 00055 void chMtxInit(Mutex *mp); 00056 void chMtxLock(Mutex *mp); 00057 void chMtxLockS(Mutex *mp); 00058 bool_t chMtxTryLock(Mutex *mp); 00059 bool_t chMtxTryLockS(Mutex *mp); 00060 Mutex *chMtxUnlock(void); 00061 Mutex *chMtxUnlockS(void); 00062 void chMtxUnlockAll(void); 00063 #ifdef __cplusplus 00064 } 00065 #endif 00066 00067 /** 00068 * @brief Data part of a static mutex initializer. 00069 * @details This macro should be used when statically initializing a mutex 00070 * that is part of a bigger structure. 00071 * 00072 * @param[in] name the name of the mutex variable 00073 */ 00074 #define _MUTEX_DATA(name) {_THREADSQUEUE_DATA(name.m_queue), NULL, NULL} 00075 00076 /** 00077 * @brief Static mutex initializer. 00078 * @details Statically initialized mutexes require no explicit initialization 00079 * using @p chMtxInit(). 00080 * 00081 * @param[in] name the name of the mutex variable 00082 */ 00083 #define MUTEX_DECL(name) Mutex name = _MUTEX_DATA(name) 00084 00085 /** 00086 * @brief Returns @p TRUE if the mutex queue contains at least a waiting 00087 * thread. 00088 */ 00089 #define chMtxQueueNotEmptyS(mp) notempty(&(mp)->m_queue) 00090 00091 #endif /* CH_USE_MUTEXES */ 00092 00093 #endif /* _CHMTX_H_ */ 00094 00095 /** @} */