source: rtems/cpukit/score/src/corerwlockobtainread.c @ 2d7ae960

4.115
Last change on this file since 2d7ae960 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: 2.9 KB
Line 
1/*
2 *  SuperCore RWLock Handler -- Obtain RWLock for reading
3 *
4 *  COPYRIGHT (c) 1989-2006.
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/corerwlock.h>
18#include <rtems/score/states.h>
19#include <rtems/score/thread.h>
20#include <rtems/score/watchdog.h>
21
22/*
23 *  _CORE_rwlock_Obtain_for_reading
24 *
25 *  This function waits for the rwlock to become available.  Optionally,
26 *  a limit may be placed on the duration of the spin.
27 *
28 *  Input parameters:
29 *    the_rwlock    - the rwlock control block to initialize
30 *    timeout_allowed - true if timeout allowed
31 *    timeout         - the maximum number of ticks to spin
32 *
33 *  Output parameters:  NONE
34 */
35
36void _CORE_RWLock_Obtain_for_reading(
37  CORE_RWLock_Control                 *the_rwlock,
38  Objects_Id                           id,
39  bool                                 wait,
40  Watchdog_Interval                    timeout,
41  CORE_RWLock_API_mp_support_callout   api_rwlock_mp_support
42)
43{
44  ISR_Level       level;
45  Thread_Control *executing = _Thread_Executing;
46
47  /*
48   *  If unlocked, then OK to read.
49   *  If locked for reading and no waiters, then OK to read.
50   *  If any thread is waiting, then we wait.
51   */
52
53  _ISR_Disable( level );
54    switch ( the_rwlock->current_state ) {
55      case CORE_RWLOCK_UNLOCKED:
56        the_rwlock->current_state = CORE_RWLOCK_LOCKED_FOR_READING;
57        the_rwlock->number_of_readers += 1;
58        _ISR_Enable( level );
59        executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL;
60        return;
61
62      case CORE_RWLOCK_LOCKED_FOR_READING: {
63        Thread_Control *waiter;
64        waiter = _Thread_queue_First( &the_rwlock->Wait_queue );
65        if ( !waiter ) {
66          the_rwlock->number_of_readers += 1;
67          _ISR_Enable( level );
68          executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL;
69          return;
70        }
71        break;
72      }
73      case CORE_RWLOCK_LOCKED_FOR_WRITING:
74        break;
75    }
76
77    /*
78     *  If the thread is not willing to wait, then return immediately.
79     */
80
81    if ( !wait ) {
82      _ISR_Enable( level );
83      executing->Wait.return_code = CORE_RWLOCK_UNAVAILABLE;
84      return;
85    }
86
87    /*
88     *  We need to wait to enter this critical section
89     */
90
91    _Thread_queue_Enter_critical_section( &the_rwlock->Wait_queue );
92    executing->Wait.queue       = &the_rwlock->Wait_queue;
93    executing->Wait.id          = id;
94    executing->Wait.option      = CORE_RWLOCK_THREAD_WAITING_FOR_READ;
95    executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL;
96    _ISR_Enable( level );
97
98    _Thread_queue_Enqueue_with_handler(
99       &the_rwlock->Wait_queue,
100       timeout,
101       _CORE_RWLock_Timeout
102    );
103
104    /* return to API level so it can dispatch and we block */
105}
Note: See TracBrowser for help on using the repository browser.