source: rtems/cpukit/score/src/corerwlockrelease.c @ 4fc370e

4.115
Last change on this file since 4fc370e was f839bf5a, checked in by Christopher Kerl <zargyyoyo@…>, on 12/01/12 at 14:47:07

score misc: Score misc: Clean up Doxygen #10 (GCI 2012)

This patch is a task from GCI 2012 which improves the Doxygen
comments in the RTEMS source.

http://www.google-melange.com/gci/task/view/google/gci2012/7983216

  • Property mode set to 100644
File size: 2.6 KB
Line 
1/**
2 * @file
3 *
4 * @brief Releases the RWLock
5 *
6 * @ingroup ScoreRWLock
7 */
8
9/*
10 *  COPYRIGHT (c) 1989-2006.
11 *  On-Line Applications Research Corporation (OAR).
12 *
13 *  The license and distribution terms for this file may be
14 *  found in the file LICENSE in this distribution or at
15 *  http://www.rtems.com/license/LICENSE.
16 */
17
18#if HAVE_CONFIG_H
19#include "config.h"
20#endif
21
22#include <rtems/system.h>
23#include <rtems/score/corerwlock.h>
24#include <rtems/score/states.h>
25#include <rtems/score/thread.h>
26#include <rtems/score/watchdog.h>
27
28CORE_RWLock_Status _CORE_RWLock_Release(
29  CORE_RWLock_Control  *the_rwlock
30)
31{
32  ISR_Level       level;
33  Thread_Control *executing = _Thread_Executing;
34  Thread_Control *next;
35
36  /*
37   *  If unlocked, then OK to read.
38   *  Otherwise, we have to block.
39   *  If locked for reading and no waiters, then OK to read.
40   *  If any thread is waiting, then we wait.
41   */
42
43  _ISR_Disable( level );
44    if ( the_rwlock->current_state == CORE_RWLOCK_UNLOCKED){
45      _ISR_Enable( level );
46      executing->Wait.return_code = CORE_RWLOCK_UNAVAILABLE;
47      return CORE_RWLOCK_SUCCESSFUL;
48    }
49    if ( the_rwlock->current_state == CORE_RWLOCK_LOCKED_FOR_READING ) {
50        the_rwlock->number_of_readers -= 1;
51        if ( the_rwlock->number_of_readers != 0 ) {
52          /* must be unlocked again */
53          _ISR_Enable( level );
54          return CORE_RWLOCK_SUCCESSFUL;
55        }
56    }
57
58    /* CORE_RWLOCK_LOCKED_FOR_WRITING or READING with readers */
59    executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL;
60
61    /*
62     * Implicitly transition to "unlocked" and find another thread interested
63     * in obtaining this rwlock.
64     */
65    the_rwlock->current_state = CORE_RWLOCK_UNLOCKED;
66  _ISR_Enable( level );
67
68  next = _Thread_queue_Dequeue( &the_rwlock->Wait_queue );
69
70  if ( next ) {
71    if ( next->Wait.option == CORE_RWLOCK_THREAD_WAITING_FOR_WRITE ) {
72      the_rwlock->current_state = CORE_RWLOCK_LOCKED_FOR_WRITING;
73      return CORE_RWLOCK_SUCCESSFUL;
74    }
75
76    /*
77     * Must be CORE_RWLOCK_THREAD_WAITING_FOR_READING
78     */
79    the_rwlock->number_of_readers += 1;
80    the_rwlock->current_state = CORE_RWLOCK_LOCKED_FOR_READING;
81
82    /*
83     * Now see if more readers can be let go.
84     */
85    while ( 1 ) {
86      next = _Thread_queue_First( &the_rwlock->Wait_queue );
87      if ( !next ||
88           next->Wait.option == CORE_RWLOCK_THREAD_WAITING_FOR_WRITE )
89        return CORE_RWLOCK_SUCCESSFUL;
90      the_rwlock->number_of_readers += 1;
91      _Thread_queue_Extract( &the_rwlock->Wait_queue, next );
92    }
93  }
94
95  /* indentation is to match _ISR_Disable at top */
96
97  return CORE_RWLOCK_SUCCESSFUL;
98}
Note: See TracBrowser for help on using the repository browser.