source: rtems/cpukit/score/src/corespinlockwait.c @ 62181b21

4.115
Last change on this file since 62181b21 was 9b4422a2, checked in by Joel Sherrill <joel.sherrill@…>, on 05/03/12 at 15:09:24

Remove All CVS Id Strings Possible Using a Script

Script does what is expected and tries to do it as
smartly as possible.

+ remove occurrences of two blank comment lines

next to each other after Id string line removed.

+ remove entire comment blocks which only exited to

contain CVS Ids

+ If the processing left a blank line at the top of

a file, it was removed.

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/*
2 *  SuperCore Spinlock Handler -- Wait for Spinlock
3 *
4 *  COPYRIGHT (c) 1989-2009.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 */
11
12#if HAVE_CONFIG_H
13#include "config.h"
14#endif
15
16#include <rtems/system.h>
17#include <rtems/score/corespinlock.h>
18#include <rtems/score/states.h>
19#include <rtems/score/thread.h>
20#include <rtems/score/watchdog.h>
21
22/*
23 *  _CORE_spinlock_Wait
24 *
25 *  This function waits for the spinlock to become available.  Optionally,
26 *  a limit may be placed on the duration of the spin.
27 *
28 *  Input parameters:
29 *    the_spinlock - the spinlock control block to initialize
30 *    wait         - true if willing to wait
31 *    timeout      - the maximum number of ticks to spin (0 is forever)
32 *
33 *  Output parameters:  NONE
34 */
35
36CORE_spinlock_Status _CORE_spinlock_Wait(
37  CORE_spinlock_Control  *the_spinlock,
38  bool                    wait,
39  Watchdog_Interval       timeout
40)
41{
42  ISR_Level level;
43  #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
44    Watchdog_Interval       limit = _Watchdog_Ticks_since_boot + timeout;
45  #endif
46
47  _ISR_Disable( level );
48    if ( (the_spinlock->lock == CORE_SPINLOCK_LOCKED) &&
49         (the_spinlock->holder == _Thread_Executing->Object.id) ) {
50      _ISR_Enable( level );
51      return CORE_SPINLOCK_HOLDER_RELOCKING;
52    }
53    the_spinlock->users += 1;
54    for ( ;; ) {
55      if ( the_spinlock->lock == CORE_SPINLOCK_UNLOCKED ) {
56        the_spinlock->lock = CORE_SPINLOCK_LOCKED;
57        the_spinlock->holder = _Thread_Executing->Object.id;
58        _ISR_Enable( level );
59        return CORE_SPINLOCK_SUCCESSFUL;
60      }
61
62      /*
63       *  Spinlock is unavailable.  If not willing to wait, return.
64       */
65      if ( !wait ) {
66        the_spinlock->users -= 1;
67        _ISR_Enable( level );
68        return CORE_SPINLOCK_UNAVAILABLE;
69      }
70
71      #if defined(FUNCTIONALITY_NOT_CURRENTLY_USED_BY_ANY_API)
72        /*
73         *  They are willing to wait but there could be a timeout.
74         */
75        if ( timeout && (limit <= _Watchdog_Ticks_since_boot) ) {
76          the_spinlock->users -= 1;
77          _ISR_Enable( level );
78          return CORE_SPINLOCK_TIMEOUT;
79        }
80      #endif
81
82      /*
83       *  The thread is willing to spin so let's set things up so
84       *  another thread has a chance of running.  This spinlock has
85       *  to be released by either another thread or an ISR.  Since
86       *  POSIX does not say anything about ISRs, that implies that
87       *  another thread must be able to run while spinning.  We are
88       *  not blocking so that implies we are at least preemptible
89       *  and possibly time-sliced.
90       *
91       *  So first, we will enable interrpts to allow for them to happen.
92       *  Then we will "flash" the thread dispatching critical section
93       *  so other threads have a chance to run.
94       *
95       *  A spinlock cannot be deleted while it is being used so we are
96       *  safe from deletion.
97       */
98
99       _ISR_Enable( level );
100       /* An ISR could occur here */
101
102       _Thread_Enable_dispatch();
103       /* Another thread could get dispatched here */
104
105       /* Reenter the critical sections so we can attempt the lock again. */
106       _Thread_Disable_dispatch();
107
108       _ISR_Disable( level );
109    }
110
111}
Note: See TracBrowser for help on using the repository browser.