source: rtems-schedsim/schedsim/rtems/sched_cpu/rtems/score/cpusmplock.h @ 726b27c

Last change on this file since 726b27c was 726b27c, checked in by Joel Sherrill <joel.sherrill@…>, on Dec 13, 2013 at 5:01:48 PM

schedsim: Update to latest RTEMS. Works Uniprocessor

  • 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#if 0
68  unsigned int my_ticket = _Atomic_Fetch_and_increment( &lock->next_ticket );
69
70  while ( _Atomic_Load_and_acquire( &lock->now_serving ) != my_ticket ) {
71    _Wait_some_time();
72  }
73#endif
74}
75
76/**
77 * @brief Releases a CPU SMP lock.
78 *
79 * @param[in,out] lock The CPU SMP lock control.
80 */
81static inline void _CPU_SMP_lock_Release( CPU_SMP_lock_Control *lock )
82{
83#if 0
84  _Atomic_Store_and_release( &lock->now_serving, lock->now_serving + 1 );
85#endif
86}
87
88/**
89 * @brief Disables interrupts and acquires the CPU SMP lock.
90 *
91 * @param[in,out] lock The CPU SMP lock control.
92 * @param[out] isr_cookie The ISR cookie.
93 */
94#define _CPU_SMP_lock_ISR_disable_and_acquire( lock, isr_cookie ) \
95  do { \
96    _CPU_ISR_Disable( isr_cookie ); \
97    _CPU_SMP_lock_Acquire( lock ); \
98  } while (0)
99
100/**
101 * @brief Releases the CPU SMP lock and enables interrupts.
102 *
103 * @param[in,out] lock The CPU SMP lock control.
104 * @param[in] isr_cookie The ISR cookie.
105 */
106#define _CPU_SMP_lock_Release_and_ISR_enable( lock, isr_cookie ) \
107  do { \
108    _CPU_SMP_lock_Release( lock ); \
109    _CPU_ISR_Enable( isr_cookie ); \
110  } while (0)
111
112/**@}*/
113
114#ifdef __cplusplus
115}
116#endif /* __cplusplus */
117
118#endif /* _RTEMS_SCORE_NO_CPU_SMPLOCK_H */
Note: See TracBrowser for help on using the repository browser.