source: rtems/cpukit/score/src/corerwlockrelease.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.7 KB
Line 
1/*
2 *  SuperCore RWLock Handler -- Release a RWLock
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_Release
24 *
25 *  This function releases the rwlock.
26 *
27 *  Input parameters:
28 *    the_rwlock    - the rwlock control block to initialize
29 *
30 *  Output parameters:  NONE
31 */
32
33CORE_RWLock_Status _CORE_RWLock_Release(
34  CORE_RWLock_Control  *the_rwlock
35)
36{
37  ISR_Level       level;
38  Thread_Control *executing = _Thread_Executing;
39  Thread_Control *next;
40
41  /*
42   *  If unlocked, then OK to read.
43   *  Otherwise, we have to block.
44   *  If locked for reading and no waiters, then OK to read.
45   *  If any thread is waiting, then we wait.
46   */
47
48  _ISR_Disable( level );
49    if ( the_rwlock->current_state == CORE_RWLOCK_UNLOCKED){
50      _ISR_Enable( level );
51      executing->Wait.return_code = CORE_RWLOCK_UNAVAILABLE;
52      return CORE_RWLOCK_SUCCESSFUL;
53    }
54    if ( the_rwlock->current_state == CORE_RWLOCK_LOCKED_FOR_READING ) {
55        the_rwlock->number_of_readers -= 1;
56        if ( the_rwlock->number_of_readers != 0 ) {
57          /* must be unlocked again */
58          _ISR_Enable( level );
59          return CORE_RWLOCK_SUCCESSFUL;
60        }
61    }
62
63    /* CORE_RWLOCK_LOCKED_FOR_WRITING or READING with readers */
64    executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL;
65
66    /*
67     * Implicitly transition to "unlocked" and find another thread interested
68     * in obtaining this rwlock.
69     */
70    the_rwlock->current_state = CORE_RWLOCK_UNLOCKED;
71  _ISR_Enable( level );
72
73  next = _Thread_queue_Dequeue( &the_rwlock->Wait_queue );
74
75  if ( next ) {
76    if ( next->Wait.option == CORE_RWLOCK_THREAD_WAITING_FOR_WRITE ) {
77      the_rwlock->current_state = CORE_RWLOCK_LOCKED_FOR_WRITING;
78      return CORE_RWLOCK_SUCCESSFUL;
79    }
80
81    /*
82     * Must be CORE_RWLOCK_THREAD_WAITING_FOR_READING
83     */
84    the_rwlock->number_of_readers += 1;
85    the_rwlock->current_state = CORE_RWLOCK_LOCKED_FOR_READING;
86
87    /*
88     * Now see if more readers can be let go.
89     */
90    while ( 1 ) {
91      next = _Thread_queue_First( &the_rwlock->Wait_queue );
92      if ( !next ||
93           next->Wait.option == CORE_RWLOCK_THREAD_WAITING_FOR_WRITE )
94        return CORE_RWLOCK_SUCCESSFUL;
95      the_rwlock->number_of_readers += 1;
96      _Thread_queue_Extract( &the_rwlock->Wait_queue, next );
97    }
98  }
99
100  /* indentation is to match _ISR_Disable at top */
101
102  return CORE_RWLOCK_SUCCESSFUL;
103}
Note: See TracBrowser for help on using the repository browser.