source: rtems/cpukit/score/src/corerwlockobtainwrite.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: 2.6 KB
Line 
1/*
2 *  SuperCore RWLock Handler -- Obtain RWLock for writing
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_writing
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_writing(
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   *  Otherwise, we have to block.
50   *  If locked for reading and no waiters, then OK to read.
51   *  If any thread is waiting, then we wait.
52   */
53
54  _ISR_Disable( level );
55    switch ( the_rwlock->current_state ) {
56      case CORE_RWLOCK_UNLOCKED:
57        the_rwlock->current_state = CORE_RWLOCK_LOCKED_FOR_WRITING;
58        _ISR_Enable( level );
59        executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL;
60        return;
61
62      case CORE_RWLOCK_LOCKED_FOR_READING:
63      case CORE_RWLOCK_LOCKED_FOR_WRITING:
64        break;
65    }
66
67    /*
68     *  If the thread is not willing to wait, then return immediately.
69     */
70
71    if ( !wait ) {
72      _ISR_Enable( level );
73      executing->Wait.return_code = CORE_RWLOCK_UNAVAILABLE;
74      return;
75    }
76
77    /*
78     *  We need to wait to enter this critical section
79     */
80
81    _Thread_queue_Enter_critical_section( &the_rwlock->Wait_queue );
82    executing->Wait.queue       = &the_rwlock->Wait_queue;
83    executing->Wait.id          = id;
84    executing->Wait.option      = CORE_RWLOCK_THREAD_WAITING_FOR_WRITE;
85    executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL;
86    _ISR_Enable( level );
87
88    _Thread_queue_Enqueue_with_handler(
89       &the_rwlock->Wait_queue,
90       timeout,
91       _CORE_RWLock_Timeout
92    );
93
94
95    /* return to API level so it can dispatch and we block */
96}
Note: See TracBrowser for help on using the repository browser.