        -:    0:Source:../../../os/rt/include/chmtx.h
        -:    0:Programs:15
        -:    1:/*
        -:    2:    ChibiOS - Copyright (C) 2006..2016 Giovanni Di Sirio.
        -:    3:
        -:    4:    This file is part of ChibiOS.
        -:    5:
        -:    6:    ChibiOS is free software; you can redistribute it and/or modify
        -:    7:    it under the terms of the GNU General Public License as published by
        -:    8:    the Free Software Foundation; either version 3 of the License, or
        -:    9:    (at your option) any later version.
        -:   10:
        -:   11:    ChibiOS is distributed in the hope that it will be useful,
        -:   12:    but WITHOUT ANY WARRANTY; without even the implied warranty of
        -:   13:    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
        -:   14:    GNU General Public License for more details.
        -:   15:
        -:   16:    You should have received a copy of the GNU General Public License
        -:   17:    along with this program.  If not, see <http://www.gnu.org/licenses/>.
        -:   18:*/
        -:   19:
        -:   20:/**
        -:   21: * @file    chmtx.h
        -:   22: * @brief   Mutexes macros and structures.
        -:   23: *
        -:   24: * @addtogroup mutexes
        -:   25: * @{
        -:   26: */
        -:   27:
        -:   28:#ifndef CHMTX_H
        -:   29:#define CHMTX_H
        -:   30:
        -:   31:#if (CH_CFG_USE_MUTEXES == TRUE) || defined(__DOXYGEN__)
        -:   32:
        -:   33:/*===========================================================================*/
        -:   34:/* Module constants.                                                         */
        -:   35:/*===========================================================================*/
        -:   36:
        -:   37:/*===========================================================================*/
        -:   38:/* Module pre-compile time settings.                                         */
        -:   39:/*===========================================================================*/
        -:   40:
        -:   41:/*===========================================================================*/
        -:   42:/* Derived constants and error checks.                                       */
        -:   43:/*===========================================================================*/
        -:   44:
        -:   45:/*===========================================================================*/
        -:   46:/* Module data structures and types.                                         */
        -:   47:/*===========================================================================*/
        -:   48:
        -:   49:/**
        -:   50: * @brief   Type of a mutex structure.
        -:   51: */
        -:   52:typedef struct ch_mutex mutex_t;
        -:   53:
        -:   54:/**
        -:   55: * @brief   Mutex structure.
        -:   56: */
        -:   57:struct ch_mutex {
        -:   58:  threads_queue_t       queue;      /**< @brief Queue of the threads sleeping
        -:   59:                                                on this mutex.              */
        -:   60:  thread_t              *owner;     /**< @brief Owner @p thread_t pointer or
        -:   61:                                                @p NULL.                    */
        -:   62:  mutex_t               *next;      /**< @brief Next @p mutex_t into an
        -:   63:                                                owner-list or @p NULL.      */
        -:   64:#if (CH_CFG_USE_MUTEXES_RECURSIVE == TRUE) || defined(__DOXYGEN__)
        -:   65:  cnt_t                 cnt;        /**< @brief Mutex recursion counter.    */
        -:   66:#endif
        -:   67:};
        -:   68:
        -:   69:/*===========================================================================*/
        -:   70:/* Module macros.                                                            */
        -:   71:/*===========================================================================*/
        -:   72:
        -:   73:/**
        -:   74: * @brief   Data part of a static mutex initializer.
        -:   75: * @details This macro should be used when statically initializing a mutex
        -:   76: *          that is part of a bigger structure.
        -:   77: *
        -:   78: * @param[in] name      the name of the mutex variable
        -:   79: */
        -:   80:#if (CH_CFG_USE_MUTEXES_RECURSIVE == TRUE) || defined(__DOXYGEN__)
        -:   81:#define _MUTEX_DATA(name) {_THREADS_QUEUE_DATA(name.queue), NULL, NULL, 0}
        -:   82:#else
        -:   83:#define _MUTEX_DATA(name) {_THREADS_QUEUE_DATA(name.queue), NULL, NULL}
        -:   84:#endif
        -:   85:
        -:   86:/**
        -:   87: * @brief   Static mutex initializer.
        -:   88: * @details Statically initialized mutexes require no explicit initialization
        -:   89: *          using @p chMtxInit().
        -:   90: *
        -:   91: * @param[in] name      the name of the mutex variable
        -:   92: */
        -:   93:#define MUTEX_DECL(name) mutex_t name = _MUTEX_DATA(name)
        -:   94:
        -:   95:/*===========================================================================*/
        -:   96:/* External declarations.                                                    */
        -:   97:/*===========================================================================*/
        -:   98:
        -:   99:#ifdef __cplusplus
        -:  100:extern "C" {
        -:  101:#endif
        -:  102:  void chMtxObjectInit(mutex_t *mp);
        -:  103:  void chMtxLock(mutex_t *mp);
        -:  104:  void chMtxLockS(mutex_t *mp);
        -:  105:  bool chMtxTryLock(mutex_t *mp);
        -:  106:  bool chMtxTryLockS(mutex_t *mp);
        -:  107:  void chMtxUnlock(mutex_t *mp);
        -:  108:  void chMtxUnlockS(mutex_t *mp);
        -:  109:  void chMtxUnlockAll(void);
        -:  110:  void chMtxUnlockAllS(void);
        -:  111:#ifdef __cplusplus
        -:  112:}
        -:  113:#endif
        -:  114:
        -:  115:/*===========================================================================*/
        -:  116:/* Module inline functions.                                                  */
        -:  117:/*===========================================================================*/
        -:  118:
        -:  119:/**
        -:  120: * @brief   Returns @p true if the mutex queue contains at least a waiting
        -:  121: *          thread.
        -:  122: *
        -:  123: * @param[out] mp       pointer to a @p mutex_t structure
        -:  124: * @return              The mutex queue status.
        -:  125: *
        -:  126: * @deprecated
        -:  127: * @sclass
        -:  128: */
function chMtxQueueNotEmptyS called 35829373 returned 100% blocks executed 100%
 35829373:  129:static inline bool chMtxQueueNotEmptyS(mutex_t *mp) {
        -:  130:
        -:  131:  chDbgCheckClassS();
        -:  132:
 35829373:  133:  return queue_notempty(&mp->queue);
call    0 returned 100%
        -:  134:}
        -:  135:
        -:  136:/**
        -:  137: * @brief   Returns the next mutex in the mutexes stack of the current thread.
        -:  138: *
        -:  139: * @return              A pointer to the next mutex in the stack.
        -:  140: * @retval NULL         if the stack is empty.
        -:  141: *
        -:  142: * @sclass
        -:  143: */
        -:  144:static inline mutex_t *chMtxGetNextMutexS(void) {
        -:  145:
        -:  146:  return chThdGetSelfX()->mtxlist;
        -:  147:}
        -:  148:
        -:  149:#endif /* CH_CFG_USE_MUTEXES == TRUE */
        -:  150:
        -:  151:#endif /* CHMTX_H */
        -:  152:
        -:  153:/** @} */
