source: rtems/cpukit/include/rtems/score/smplockseq.h @ 21275b58

Last change on this file since 21275b58 was 2afb22b, checked in by Chris Johns <chrisj@…>, on Dec 23, 2017 at 7:18:56 AM

Remove make preinstall

A speciality of the RTEMS build system was the make preinstall step. It
copied header files from arbitrary locations into the build tree. The
header files were included via the -Bsome/build/tree/path GCC command
line option.

This has at least seven problems:

  • The make preinstall step itself needs time and disk space.
  • Errors in header files show up in the build tree copy. This makes it hard for editors to open the right file to fix the error.
  • There is no clear relationship between source and build tree header files. This makes an audit of the build process difficult.
  • The visibility of all header files in the build tree makes it difficult to enforce API barriers. For example it is discouraged to use BSP-specifics in the cpukit.
  • An introduction of a new build system is difficult.
  • Include paths specified by the -B option are system headers. This may suppress warnings.
  • The parallel build had sporadic failures on some hosts.

This patch removes the make preinstall step. All installed header
files are moved to dedicated include directories in the source tree.
Let @RTEMS_CPU@ be the target architecture, e.g. arm, powerpc, sparc,
etc. Let @RTEMS_BSP_FAMILIY@ be a BSP family base directory, e.g.
erc32, imx, qoriq, etc.

The new cpukit include directories are:

  • cpukit/include
  • cpukit/score/cpu/@RTEMS_CPU@/include
  • cpukit/libnetworking

The new BSP include directories are:

  • bsps/include
  • bsps/@RTEMS_CPU@/include
  • bsps/@RTEMS_CPU@/@RTEMS_BSP_FAMILIY@/include

There are build tree include directories for generated files.

The include directory order favours the most general header file, e.g.
it is not possible to override general header files via the include path
order.

The "bootstrap -p" option was removed. The new "bootstrap -H" option
should be used to regenerate the "headers.am" files.

Update #3254.

  • Property mode set to 100644
File size: 4.2 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup ScoreSMPLock
5 *
6 * @brief SMP Lock API
7 */
8
9/*
10 * Copyright (c) 2016 embedded brains GmbH
11 *
12 * The license and distribution terms for this file may be
13 * found in the file LICENSE in this distribution or at
14 * http://www.rtems.org/license/LICENSE.
15 */
16
17#ifndef _RTEMS_SCORE_SMPLOCKSEQ_H
18#define _RTEMS_SCORE_SMPLOCKSEQ_H
19
20#include <rtems/score/cpuopts.h>
21
22#if defined(RTEMS_SMP)
23
24#include <rtems/score/assert.h>
25#include <rtems/score/atomic.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif /* __cplusplus */
30
31/**
32 * @addtogroup ScoreSMPLock
33 *
34 * @{
35 */
36
37/**
38 * @brief SMP sequence lock control.
39 *
40 * The sequence lock offers a consistent data set for readers in the presence
41 * of at most one concurrent writer.  Due to the read-modify-write operation in
42 * _SMP_sequence_lock_Read_retry() the data corresponding to the last written
43 * sequence number is observed.  To allow multiple writers an additional SMP
44 * lock is necessary to serialize writes.
45 *
46 * See also Hans-J. Boehm, HP Laboratories,
47 * "Can Seqlocks Get Along With Programming Language Memory Models?",
48 * http://www.hpl.hp.com/techreports/2012/HPL-2012-68.pdf
49 */
50typedef struct {
51  /**
52   * @brief The sequence number.
53   *
54   * An odd value indicates that a write is in progress.
55   */
56  Atomic_Uint sequence;
57} SMP_sequence_lock_Control;
58
59/**
60 * @brief SMP sequence lock control initializer for static initialization.
61 */
62#define SMP_SEQUENCE_LOCK_INITIALIZER { ATOMIC_INITIALIZER_UINT( 0 ) }
63
64/**
65 * @brief Initializes an SMP sequence lock.
66 *
67 * Concurrent initialization leads to unpredictable results.
68 *
69 * @param lock The SMP sequence lock control.
70 */
71static inline void _SMP_sequence_lock_Initialize( SMP_sequence_lock_Control *lock )
72{
73  _Atomic_Init_uint( &lock->sequence, 0 );
74}
75
76/**
77 * @brief Destroys an SMP sequence lock.
78 *
79 * Concurrent destruction leads to unpredictable results.
80 *
81 * @param lock The SMP sequence lock control.
82 */
83static inline void _SMP_sequence_lock_Destroy( SMP_sequence_lock_Control *lock )
84{
85  (void) lock;
86}
87
88/**
89 * @brief Begins an SMP sequence lock write operation.
90 *
91 * This function will not disable interrupts.  The caller must ensure that the
92 * current thread of execution is not interrupted indefinite since this would
93 * starve readers.
94 *
95 * @param lock The SMP sequence lock control.
96 *
97 * @return The current sequence number.
98 */
99static inline unsigned int _SMP_sequence_lock_Write_begin(
100  SMP_sequence_lock_Control *lock
101)
102{
103  unsigned int seq;
104
105  seq = _Atomic_Load_uint( &lock->sequence, ATOMIC_ORDER_RELAXED );
106  _Assert( seq % 2 == 0 );
107
108  _Atomic_Store_uint( &lock->sequence, seq + 1, ATOMIC_ORDER_RELAXED );
109
110  /* There is no atomic store with acquire/release semantics */
111  _Atomic_Fence( ATOMIC_ORDER_ACQ_REL );
112
113  return seq;
114}
115
116/**
117 * @brief Ends an SMP sequence lock write operation.
118 *
119 * @param lock The SMP sequence lock control.
120 * @param seq The sequence number returned by _SMP_sequence_lock_Write_begin().
121 */
122static inline void _SMP_sequence_lock_Write_end(
123  SMP_sequence_lock_Control *lock,
124  unsigned int               seq
125)
126{
127  _Atomic_Store_uint( &lock->sequence, seq + 2, ATOMIC_ORDER_RELEASE );
128}
129
130/**
131 * @brief Begins an SMP sequence lock read operation.
132 *
133 * This function will not disable interrupts.
134 *
135 * @param lock The SMP sequence lock control.
136 *
137 * @return The current sequence number.
138 */
139static inline unsigned int _SMP_sequence_lock_Read_begin(
140  const SMP_sequence_lock_Control *lock
141)
142{
143  return _Atomic_Load_uint( &lock->sequence, ATOMIC_ORDER_ACQUIRE );
144}
145
146/**
147 * @brief Ends an SMP sequence lock read operation and indicates if a retry is
148 * necessary.
149 *
150 * @param lock The SMP sequence lock control.
151 * @param seq The sequence number returned by _SMP_sequence_lock_Read_begin().
152 *
153 * @retval true The read operation must be retried with a call to
154 *   _SMP_sequence_lock_Read_begin().
155 * @retval false Otherwise.
156 */
157static inline bool _SMP_sequence_lock_Read_retry(
158  SMP_sequence_lock_Control *lock,
159  unsigned int               seq
160)
161{
162  unsigned int seq2;
163
164  seq2 = _Atomic_Fetch_add_uint( &lock->sequence, 0, ATOMIC_ORDER_RELEASE );
165  return seq != seq2 || seq % 2 != 0;
166}
167
168/**@}*/
169
170#ifdef __cplusplus
171}
172#endif /* __cplusplus */
173
174#endif /* RTEMS_SMP */
175
176#endif /* _RTEMS_SCORE_SMPLOCKSEQ_H */
Note: See TracBrowser for help on using the repository browser.