Back to home page

LXR

 
 

    


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

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup RTEMSAPIClassicChains
0007  *
0008  * @brief This source file contains the implementation of rtems_chain_append(),
0009  *   rtems_chain_append_with_empty_check(), rtems_chain_extract(),
0010  *   rtems_chain_get(), rtems_chain_get_with_empty_check(),
0011  *   rtems_chain_insert(), rtems_chain_prepend(), and
0012  *   rtems_chain_prepend_with_empty_check().
0013  */
0014 
0015 /*
0016  * Copyright (C) 2013, 2016 embedded brains GmbH & Co. KG
0017  *
0018  * Redistribution and use in source and binary forms, with or without
0019  * modification, are permitted provided that the following conditions
0020  * are met:
0021  * 1. Redistributions of source code must retain the above copyright
0022  *    notice, this list of conditions and the following disclaimer.
0023  * 2. Redistributions in binary form must reproduce the above copyright
0024  *    notice, this list of conditions and the following disclaimer in the
0025  *    documentation and/or other materials provided with the distribution.
0026  *
0027  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0028  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0029  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0030  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0031  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0032  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0033  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0034  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0035  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0036  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0037  * POSSIBILITY OF SUCH DAMAGE.
0038  */
0039 
0040 #ifdef HAVE_CONFIG_H
0041 #include "config.h"
0042 #endif
0043 
0044 #include <rtems/chain.h>
0045 #include <rtems/rtems/intr.h>
0046 
0047 RTEMS_INTERRUPT_LOCK_DEFINE( static, chain_lock, "Chains" )
0048 
0049 static void chain_acquire( rtems_interrupt_lock_context *lock_context )
0050 {
0051   rtems_interrupt_lock_acquire( &chain_lock, lock_context );
0052 }
0053 
0054 static void chain_release( rtems_interrupt_lock_context *lock_context )
0055 {
0056   rtems_interrupt_lock_release( &chain_lock, lock_context );
0057 }
0058 
0059 void rtems_chain_extract( rtems_chain_node *node )
0060 {
0061   rtems_interrupt_lock_context lock_context;
0062 
0063   chain_acquire( &lock_context );
0064   _Chain_Extract_unprotected( node );
0065   chain_release( &lock_context );
0066 }
0067 
0068 rtems_chain_node *rtems_chain_get( rtems_chain_control *chain )
0069 {
0070   rtems_chain_node *node;
0071   rtems_interrupt_lock_context lock_context;
0072 
0073   chain_acquire( &lock_context );
0074   node = _Chain_Get_unprotected( chain );
0075   chain_release( &lock_context );
0076 
0077   return node;
0078 }
0079 
0080 void rtems_chain_insert( rtems_chain_node *after_node, rtems_chain_node *node )
0081 {
0082   rtems_interrupt_lock_context lock_context;
0083 
0084   chain_acquire( &lock_context );
0085   _Chain_Insert_unprotected( after_node, node );
0086   chain_release( &lock_context );
0087 }
0088 
0089 void rtems_chain_append(
0090   rtems_chain_control *chain,
0091   rtems_chain_node *node
0092 )
0093 {
0094   rtems_interrupt_lock_context lock_context;
0095 
0096   chain_acquire( &lock_context );
0097   _Chain_Append_unprotected( chain, node );
0098   chain_release( &lock_context );
0099 }
0100 
0101 void rtems_chain_prepend(
0102   rtems_chain_control *chain,
0103   rtems_chain_node *node
0104 )
0105 {
0106   rtems_interrupt_lock_context lock_context;
0107 
0108   chain_acquire( &lock_context );
0109   _Chain_Prepend_unprotected( chain, node );
0110   chain_release( &lock_context );
0111 }
0112 
0113 bool rtems_chain_append_with_empty_check(
0114   rtems_chain_control *chain,
0115   rtems_chain_node *node
0116 )
0117 {
0118   bool was_empty;
0119   rtems_interrupt_lock_context lock_context;
0120 
0121   chain_acquire( &lock_context );
0122   was_empty = _Chain_Append_with_empty_check_unprotected( chain, node );
0123   chain_release( &lock_context );
0124 
0125   return was_empty;
0126 }
0127 
0128 bool rtems_chain_prepend_with_empty_check(
0129   rtems_chain_control *chain,
0130   rtems_chain_node *node
0131 )
0132 {
0133   bool was_empty;
0134   rtems_interrupt_lock_context lock_context;
0135 
0136   chain_acquire( &lock_context );
0137   was_empty = _Chain_Prepend_with_empty_check_unprotected( chain, node );
0138   chain_release( &lock_context );
0139 
0140   return was_empty;
0141 }
0142 
0143 bool rtems_chain_get_with_empty_check(
0144   rtems_chain_control *chain,
0145   rtems_chain_node **node
0146 )
0147 {
0148   bool is_empty_now;
0149   rtems_interrupt_lock_context lock_context;
0150 
0151   chain_acquire( &lock_context );
0152   is_empty_now = _Chain_Get_with_empty_check_unprotected( chain, node );
0153   chain_release( &lock_context );
0154 
0155   return is_empty_now;
0156 }