source: rtems/cpukit/include/rtems/score/semaphoreimpl.h @ 7b85efb8

Last change on this file since 7b85efb8 was 7b85efb8, checked in by Joel Sherrill <joel@…>, on 02/16/22 at 21:16:11

cpukit/include/rtems/score/[s-z]*.h: Change license to BSD-2

Updates #3053.

  • Property mode set to 100644
File size: 3.8 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup RTEMSScoreSyslockSemaphore
7 *
8 * @brief This header file provides the interfaces of the
9 *   @ref RTEMSScoreSyslockSemaphore.
10 */
11
12/*
13 * Copyright (c) 2015, 2017 embedded brains GmbH.  All rights reserved.
14 *
15 *  embedded brains GmbH
16 *  Dornierstr. 4
17 *  82178 Puchheim
18 *  Germany
19 *  <rtems@embedded-brains.de>
20 *
21 * Redistribution and use in source and binary forms, with or without
22 * modification, are permitted provided that the following conditions
23 * are met:
24 * 1. Redistributions of source code must retain the above copyright
25 *    notice, this list of conditions and the following disclaimer.
26 * 2. Redistributions in binary form must reproduce the above copyright
27 *    notice, this list of conditions and the following disclaimer in the
28 *    documentation and/or other materials provided with the distribution.
29 *
30 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
31 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
34 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
35 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
36 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
38 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40 * POSSIBILITY OF SUCH DAMAGE.
41 */
42
43#ifndef _RTEMS_SCORE_SEMAPHOREIMPL_H
44#define _RTEMS_SCORE_SEMAPHOREIMPL_H
45
46#include <sys/lock.h>
47
48#include <rtems/score/percpu.h>
49#include <rtems/score/threadqimpl.h>
50
51/**
52 * @defgroup RTEMSScoreSyslockSemaphore System Lock Semaphore Support
53 *
54 * @ingroup RTEMSScore
55 *
56 * @brief The System Lock Semaphore Support helps to implement directives which
57 *   use data structures compatible with the data structures defined by the
58 *   Newlib provided <sys/lock.h> header file.
59 *
60 * @{
61 */
62
63#ifdef __cplusplus
64extern "C" {
65#endif /* __cplusplus */
66
67typedef struct {
68  Thread_queue_Syslock_queue Queue;
69  unsigned int count;
70} Sem_Control;
71
72#define SEMAPHORE_TQ_OPERATIONS &_Thread_queue_Operations_priority
73
74/**
75 * @brief Gets the Sem_Control * of the semaphore.
76 *
77 * @param sem The Semaphore_Control * to cast to Sem_Control *.
78 *
79 * @return @a sem cast to Sem_Control *.
80 */
81static inline Sem_Control *_Sem_Get( struct _Semaphore_Control *_sem )
82{
83  return (Sem_Control *) _sem;
84}
85
86/**
87 * @brief Acquires the semaphore queue critical.
88 *
89 * This routine acquires the semaphore.
90 *
91 * @param[in, out] sem The semaphore to acquire the queue of.
92 * @param queue_context The thread queue context.
93 *
94 * @return The executing thread.
95 */
96static inline Thread_Control *_Sem_Queue_acquire_critical(
97  Sem_Control          *sem,
98  Thread_queue_Context *queue_context
99)
100{
101  Thread_Control *executing;
102
103  executing = _Thread_Executing;
104  _Thread_queue_Queue_acquire_critical(
105    &sem->Queue.Queue,
106    &executing->Potpourri_stats,
107    &queue_context->Lock_context.Lock_context
108  );
109
110  return executing;
111}
112
113/**
114 * @brief Releases the semaphore queue.
115 *
116 * @param[in, out] sem The semaphore to release the queue of.
117 * @param level The interrupt level value to restore the interrupt status on the processor.
118 * @param queue_context The thread queue context.
119 */
120static inline void _Sem_Queue_release(
121  Sem_Control          *sem,
122  ISR_Level             level,
123  Thread_queue_Context *queue_context
124)
125{
126  _Thread_queue_Queue_release_critical(
127    &sem->Queue.Queue,
128    &queue_context->Lock_context.Lock_context
129  );
130  _ISR_Local_enable( level );
131}
132
133#ifdef __cplusplus
134}
135#endif /* __cplusplus */
136
137/** @} */
138
139#endif /* _RTEMS_SCORE_SEMAPHOREIMPL_H */
Note: See TracBrowser for help on using the repository browser.