![]() |
|
|||
File indexing completed on 2025-05-11 08:24:13
0001 /* SPDX-License-Identifier: BSD-2-Clause */ 0002 0003 /** 0004 * @file 0005 * 0006 * @ingroup RTEMSScoreSyslockSemaphore 0007 * 0008 * @brief This header file provides the interfaces of the 0009 * @ref RTEMSScoreSyslockSemaphore. 0010 */ 0011 0012 /* 0013 * Copyright (C) 2015, 2017 embedded brains GmbH & Co. KG 0014 * 0015 * Redistribution and use in source and binary forms, with or without 0016 * modification, are permitted provided that the following conditions 0017 * are met: 0018 * 1. Redistributions of source code must retain the above copyright 0019 * notice, this list of conditions and the following disclaimer. 0020 * 2. Redistributions in binary form must reproduce the above copyright 0021 * notice, this list of conditions and the following disclaimer in the 0022 * documentation and/or other materials provided with the distribution. 0023 * 0024 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 0025 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 0026 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 0027 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 0028 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 0029 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 0030 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 0031 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 0032 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 0033 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 0034 * POSSIBILITY OF SUCH DAMAGE. 0035 */ 0036 0037 #ifndef _RTEMS_SCORE_SEMAPHOREIMPL_H 0038 #define _RTEMS_SCORE_SEMAPHOREIMPL_H 0039 0040 #include <sys/lock.h> 0041 0042 #include <rtems/score/percpu.h> 0043 #include <rtems/score/threadqimpl.h> 0044 0045 /** 0046 * @defgroup RTEMSScoreSyslockSemaphore System Lock Semaphore Support 0047 * 0048 * @ingroup RTEMSScore 0049 * 0050 * @brief The System Lock Semaphore Support helps to implement directives which 0051 * use data structures compatible with the data structures defined by the 0052 * Newlib provided <sys/lock.h> header file. 0053 * 0054 * @{ 0055 */ 0056 0057 #ifdef __cplusplus 0058 extern "C" { 0059 #endif /* __cplusplus */ 0060 0061 typedef struct { 0062 Thread_queue_Syslock_queue Queue; 0063 unsigned int count; 0064 } Sem_Control; 0065 0066 #define SEMAPHORE_TQ_OPERATIONS &_Thread_queue_Operations_priority 0067 0068 /** 0069 * @brief Gets the Sem_Control * of the semaphore. 0070 * 0071 * @param sem The Semaphore_Control * to cast to Sem_Control *. 0072 * 0073 * @return @a sem cast to Sem_Control *. 0074 */ 0075 static inline Sem_Control *_Sem_Get( struct _Semaphore_Control *_sem ) 0076 { 0077 return (Sem_Control *) _sem; 0078 } 0079 0080 /** 0081 * @brief Acquires the semaphore queue critical. 0082 * 0083 * This routine acquires the semaphore. 0084 * 0085 * @param[in, out] sem The semaphore to acquire the queue of. 0086 * @param queue_context The thread queue context. 0087 * 0088 * @return The executing thread. 0089 */ 0090 static inline Thread_Control *_Sem_Queue_acquire_critical( 0091 Sem_Control *sem, 0092 Thread_queue_Context *queue_context 0093 ) 0094 { 0095 Thread_Control *executing; 0096 0097 executing = _Thread_Executing; 0098 _Thread_queue_Queue_acquire_critical( 0099 &sem->Queue.Queue, 0100 &executing->Potpourri_stats, 0101 &queue_context->Lock_context.Lock_context 0102 ); 0103 0104 return executing; 0105 } 0106 0107 /** 0108 * @brief Releases the semaphore queue. 0109 * 0110 * @param[in, out] sem The semaphore to release the queue of. 0111 * @param level The interrupt level value to restore the interrupt status on the processor. 0112 * @param queue_context The thread queue context. 0113 */ 0114 static inline void _Sem_Queue_release( 0115 Sem_Control *sem, 0116 ISR_Level level, 0117 Thread_queue_Context *queue_context 0118 ) 0119 { 0120 _Thread_queue_Queue_release_critical( 0121 &sem->Queue.Queue, 0122 &queue_context->Lock_context.Lock_context 0123 ); 0124 _ISR_Local_enable( level ); 0125 } 0126 0127 #ifdef __cplusplus 0128 } 0129 #endif /* __cplusplus */ 0130 0131 /** @} */ 0132 0133 #endif /* _RTEMS_SCORE_SEMAPHOREIMPL_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
![]() ![]() |