source: rtems/cpukit/score/cpu/no_cpu/rtems/score/cpusmplock.h @ 98239f3

4.115
Last change on this file since 98239f3 was 961669d, checked in by Sebastian Huber <sebastian.huber@…>, on 06/14/13 at 13:30:37

documentation: Fix Doxygen comments

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/**
2 * @file
3 *
4 * @ingroup ScoreSMPLockCPU
5 *
6 * @brief CPU SMP Lock Implementation
7 */
8
9/*
10 * Copyright (c) 2013 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.com/license/LICENSE.
15 */
16
17#ifndef _RTEMS_SCORE_NO_CPU_SMPLOCK_H
18#define _RTEMS_SCORE_NO_CPU_SMPLOCK_H
19
20#include <rtems/score/cpu.h>
21
22#ifdef __cplusplus
23extern "C" {
24#endif /* __cplusplus */
25
26/**
27 * @defgroup ScoreSMPLockCPU CPU SMP Locks
28 *
29 * @ingroup ScoreSMPLock
30 *
31 * This example will implement a ticket lock.
32 *
33 * @{
34 */
35
36/**
37 * @brief CPU SMP lock control.
38 */
39typedef struct {
40  unsigned int next_ticket;
41  unsigned int now_serving;
42} CPU_SMP_lock_Control;
43
44/**
45 * @brief CPU SMP lock control initializer for static initialization.
46 */
47#define CPU_SMP_LOCK_INITIALIZER { 0, 0 }
48
49/**
50 * @brief Initializes a CPU SMP lock control.
51 *
52 * @param[out] lock The CPU SMP lock control.
53 */
54static inline void _CPU_SMP_lock_Initialize( CPU_SMP_lock_Control *lock )
55{
56  lock->next_ticket = 0;
57  lock->now_serving = 0;
58}
59
60/**
61 * @brief Acquires a CPU SMP lock.
62 *
63 * @param[in,out] lock The CPU SMP lock control.
64 */
65static inline void _CPU_SMP_lock_Acquire( CPU_SMP_lock_Control *lock )
66{
67  unsigned int my_ticket = _Atomic_Fetch_and_increment( &lock->next_ticket );
68
69  while ( _Atomic_Load_and_acquire( &lock->now_serving ) != my_ticket ) {
70    _Wait_some_time();
71  }
72}
73
74/**
75 * @brief Releases a CPU SMP lock.
76 *
77 * @param[in,out] lock The CPU SMP lock control.
78 */
79static inline void _CPU_SMP_lock_Release( CPU_SMP_lock_Control *lock )
80{
81  _Atomic_Store_and_release( &lock->now_serving, lock->now_serving + 1 );
82}
83
84/**
85 * @brief Disables interrupts and acquires the CPU SMP lock.
86 *
87 * @param[in,out] lock The CPU SMP lock control.
88 * @param[out] isr_cookie The ISR cookie.
89 */
90#define _CPU_SMP_lock_ISR_disable_and_acquire( lock, isr_cookie ) \
91  do { \
92    _CPU_ISR_Disable( isr_cookie ); \
93    _CPU_SMP_lock_Acquire( lock ); \
94  } while (0)
95
96/**
97 * @brief Releases the CPU SMP lock and enables interrupts.
98 *
99 * @param[in,out] lock The CPU SMP lock control.
100 * @param[in] isr_cookie The ISR cookie.
101 */
102#define _CPU_SMP_lock_Release_and_ISR_enable( lock, isr_cookie ) \
103  do { \
104    _CPU_SMP_lock_Release( lock ); \
105    _CPU_ISR_Enable( isr_cookie ); \
106  } while (0)
107
108/**@}*/
109
110#ifdef __cplusplus
111}
112#endif /* __cplusplus */
113
114#endif /* _RTEMS_SCORE_NO_CPU_SMPLOCK_H */
Note: See TracBrowser for help on using the repository browser.