source: rtems/cpukit/score/include/rtems/score/corespinlockimpl.h @ 9ec7d492

5
Last change on this file since 9ec7d492 was 9ec7d492, checked in by Sebastian Huber <sebastian.huber@…>, on 05/25/16 at 06:37:28

posix: Fix pthread_spin_unlock() error status

Close #2719.

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/**
2 * @file
3 *
4 * @brief Inlined Routines Associated with the SuperCore Spinlock
5 *
6 * This include file contains all of the inlined routines associated
7 * with the SuperCore spinlock.
8 */
9
10/*
11 *  COPYRIGHT (c) 1989-2008.
12 *  On-Line Applications Research Corporation (OAR).
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.org/license/LICENSE.
17 */
18
19#ifndef _RTEMS_SCORE_CORESPINLOCKIMPL_H
20#define _RTEMS_SCORE_CORESPINLOCKIMPL_H
21
22#include <rtems/score/corespinlock.h>
23#include <rtems/score/watchdog.h>
24
25#include <string.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31/**
32 * @addtogroup ScoreSpinlock
33 */
34/**@{**/
35
36/**
37 *  Core Spinlock handler return statuses.
38 */
39typedef enum {
40  /** This status indicates that the operation completed successfully. */
41  CORE_SPINLOCK_SUCCESSFUL,
42  /** This status indicates that the current thread already holds the spinlock.
43   *  An attempt to relock it will result in deadlock.
44   */
45  CORE_SPINLOCK_HOLDER_RELOCKING,
46  /** This status indicates that the current thread is attempting to unlock a
47   *  spinlock that is held by another thread.
48   */
49  CORE_SPINLOCK_NOT_HOLDER,
50  /** This status indicates that a thread reached the limit of time it
51   *  was willing to wait on the spin lock.
52   */
53  CORE_SPINLOCK_TIMEOUT,
54  /** This status indicates that a thread is currently waiting for this
55   *  spin lock.
56   */
57  CORE_SPINLOCK_IS_BUSY,
58  /** This status indicates that the spinlock is currently locked and thus
59   *  unavailable.
60   */
61  CORE_SPINLOCK_UNAVAILABLE
62}   CORE_spinlock_Status;
63
64/** This is a shorthand for the last status code. */
65#define CORE_SPINLOCK_STATUS_LAST CORE_SPINLOCK_UNAVAILABLE
66
67/** This indicates the lock is available. */
68#define CORE_SPINLOCK_UNLOCKED 0
69
70/** This indicates the lock is unavailable. */
71#define CORE_SPINLOCK_LOCKED   1
72
73/**
74 *  @brief Initialize the spinlock.
75 *
76 *  This routine initializes the spinlock based on the parameters passed.
77 *
78 *  @param[in] the_spinlock is the spinlock control block to initialize
79 */
80RTEMS_INLINE_ROUTINE void _CORE_spinlock_Initialize(
81  CORE_spinlock_Control *the_spinlock
82)
83{
84  memset( the_spinlock, 0, sizeof( *the_spinlock ) );
85}
86
87RTEMS_INLINE_ROUTINE void _CORE_spinlock_Acquire_critical(
88  CORE_spinlock_Control *the_spinlock,
89  ISR_lock_Context      *lock_context
90)
91{
92  _ISR_lock_Acquire( &the_spinlock->Lock, lock_context );
93}
94
95RTEMS_INLINE_ROUTINE void _CORE_spinlock_Release(
96  CORE_spinlock_Control *the_spinlock,
97  ISR_lock_Context      *lock_context
98)
99{
100  _ISR_lock_Release_and_ISR_enable( &the_spinlock->Lock, lock_context );
101}
102
103/**
104 *  @brief Wait for spinlock.
105 *
106 *  This routine wait for the spinlock to be released.  If the spinlock
107 *  is set to automatic and this is the appropriate thread, then it returns
108 *  immediately.  Otherwise, the calling thread is blocked until the spinlock
109 *  is released.
110 *
111 *  @param[in] the_spinlock is the spinlock to wait for
112 *  @param[in] wait is true if willing to wait
113 *  @param[in] timeout is the maximum number of ticks to spin (0 is forever)
114 *
115 * @retval A status is returned which indicates the success or failure of
116 *         this operation.
117 */
118CORE_spinlock_Status _CORE_spinlock_Seize(
119  CORE_spinlock_Control *the_spinlock,
120  bool                   wait,
121  Watchdog_Interval      timeout,
122  ISR_lock_Context      *lock_context
123);
124
125/**
126 * @brief Manually release the spinlock.
127 *
128 *  This routine manually releases the spinlock.  All of the threads waiting
129 *  for the spinlock will be readied.
130 *
131 *  @param[in] the_spinlock is the spinlock to surrender
132 */
133CORE_spinlock_Status _CORE_spinlock_Surrender(
134  CORE_spinlock_Control *the_spinlock,
135  ISR_lock_Context      *lock_context
136);
137
138/**
139 * This method is used to determine if the spinlock is available or not.
140 *
141 * @param[in] the_spinlock will be checked
142 *
143 * @return This method will return true if the spinlock is busy
144 *         and false otherwise.
145 */
146RTEMS_INLINE_ROUTINE bool _CORE_spinlock_Is_busy(
147  CORE_spinlock_Control  *the_spinlock
148)
149{
150  return (the_spinlock->users != 0);
151}
152
153/** @} */
154
155#ifdef __cplusplus
156}
157#endif
158
159#endif
160/* end of include file */
Note: See TracBrowser for help on using the repository browser.