source: rtems/cpukit/score/include/rtems/score/corespinlock.h @ a1f9934a

4.115
Last change on this file since a1f9934a was a1f9934a, checked in by Mathew Kallada <matkallada@…>, on 01/04/13 at 15:01:21

score: Doxygen Clean Up Task #3

  • Property mode set to 100644
File size: 4.6 KB
Line 
1/**
2 *  @file  rtems/score/corespinlock.h
3 *
4 *  @brief Constants and Structures Associated with the Spinlock Handler
5 *
6 *  This include file contains all the constants and structures associated
7 *  with the Spinlock Handler.
8 */
9
10/*
11 *  COPYRIGHT (c) 1989-2006.
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.com/license/LICENSE.
17 */
18
19#ifndef _RTEMS_SCORE_CORESPINLOCK_H
20#define _RTEMS_SCORE_CORESPINLOCK_H
21
22/**
23 *  @defgroup ScoreSpinlock Spinlock Handler
24 *
25 *  @ingroup Score
26 *
27 *  This handler encapsulates functionality which provides the foundation
28 *  Spinlock services used in all of the APIs supported by RTEMS.
29 */
30/**@{*/
31
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36#include <rtems/score/thread.h>
37#include <rtems/score/priority.h>
38
39/**
40 *  Core Spinlock handler return statuses.
41 */
42typedef enum {
43  /** This status indicates that the operation completed successfully. */
44  CORE_SPINLOCK_SUCCESSFUL,
45  /** This status indicates that the current thread already holds the spinlock.
46   *  An attempt to relock it will result in deadlock.
47   */
48  CORE_SPINLOCK_HOLDER_RELOCKING,
49  /** This status indicates that the current thread is attempting to unlock a
50   *  spinlock that is held by another thread.
51   */
52  CORE_SPINLOCK_NOT_HOLDER,
53  /** This status indicates that a thread reached the limit of time it
54   *  was willing to wait on the spin lock.
55   */
56  CORE_SPINLOCK_TIMEOUT,
57  /** This status indicates that a thread is currently waiting for this
58   *  spin lock.
59   */
60  CORE_SPINLOCK_IS_BUSY,
61  /** This status indicates that the spinlock is currently locked and thus
62   *  unavailable.
63   */
64  CORE_SPINLOCK_UNAVAILABLE,
65  /** This status indicates that the spinlock is not currently locked and thus
66   *  should not be released.
67   */
68  CORE_SPINLOCK_NOT_LOCKED
69}   CORE_spinlock_Status;
70
71/** This is a shorthand for the last status code. */
72#define CORE_SPINLOCK_STATUS_LAST CORE_SPINLOCK_NOT_LOCKED
73
74/** This indicates the lock is available. */
75#define CORE_SPINLOCK_UNLOCKED 0
76
77/** This indicates the lock is unavailable. */
78#define CORE_SPINLOCK_LOCKED   1
79
80/**
81 *  The following defines the control block used to manage the
82 *  attributes of each spinlock.
83 */
84typedef struct {
85  /** This element indicates XXX
86   */
87  uint32_t                  XXX;
88}   CORE_spinlock_Attributes;
89
90/**
91 *  The following defines the control block used to manage each
92 *  spinlock.
93 */
94typedef struct {
95  /** XXX may not be needed */
96  CORE_spinlock_Attributes  Attributes;
97
98  /** This field is the lock.
99   */
100  volatile uint32_t     lock;
101
102  /** This field is a count of the current number of threads using
103   *  this spinlock.  It includes the thread holding the lock as well
104   *  as those waiting.
105   */
106  volatile uint32_t     users;
107
108  /** This field is the Id of the thread holding the lock.  It may or may
109   *  not be the thread which acquired it.
110   */
111  volatile Objects_Id   holder;
112}   CORE_spinlock_Control;
113
114/**
115 *  @brief Initialize the spinlock.
116 *
117 *  This routine initializes the spinlock based on the parameters passed.
118 *
119 *  @param[in] the_spinlock is the spinlock control block to initialize
120 *  @param[in] the_spinlock_attributes define the behavior of this instance
121 */
122void _CORE_spinlock_Initialize(
123  CORE_spinlock_Control       *the_spinlock,
124  CORE_spinlock_Attributes    *the_spinlock_attributes
125);
126
127/**
128 *  @brief Wait for spinlock.
129 *
130 *  This routine wait for the spinlock to be released.  If the spinlock
131 *  is set to automatic and this is the appropriate thread, then it returns
132 *  immediately.  Otherwise, the calling thread is blocked until the spinlock
133 *  is released.
134 *
135 *  @param[in] the_spinlock is the spinlock to wait for
136 *  @param[in] wait is true if willing to wait
137 *  @param[in] timeout is the maximum number of ticks to spin (0 is forever)
138 *
139 * @retval A status is returned which indicates the success or failure of
140 *         this operation.
141 */
142CORE_spinlock_Status _CORE_spinlock_Wait(
143  CORE_spinlock_Control  *the_spinlock,
144  bool                    wait,
145  Watchdog_Interval       timeout
146);
147
148/**
149 * @brief Manually release the spinlock.
150 *
151 *  This routine manually releases the spinlock.  All of the threads waiting
152 *  for the spinlock will be readied.
153 *
154 *  @param[in] the_spinlock is the spinlock to surrender
155 */
156CORE_spinlock_Status _CORE_spinlock_Release(
157  CORE_spinlock_Control *the_spinlock
158);
159
160#ifndef __RTEMS_APPLICATION__
161#include <rtems/score/corespinlock.inl>
162#endif
163
164#ifdef __cplusplus
165}
166#endif
167
168/**@}*/
169
170#endif
171/*  end of include file */
Note: See TracBrowser for help on using the repository browser.