source: rtems/cpukit/score/src/corerwlockobtainread.c @ a936aa49

4.115
Last change on this file since a936aa49 was 5a58b1e, checked in by Daniel Georgiev <daniel.georgiev95@…>, on 12/01/12 at 14:53:45

score misc: Score misc: Clean up Doxygen #11 (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/8013204

  • Property mode set to 100644
File size: 2.5 KB
Line 
1/**
2 * @file
3 *
4 * @brief Obtain RWLock for reading
5 * @ingroup ScoreRWLock
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2006.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.com/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/system.h>
22#include <rtems/score/corerwlock.h>
23#include <rtems/score/states.h>
24#include <rtems/score/thread.h>
25#include <rtems/score/watchdog.h>
26
27void _CORE_RWLock_Obtain_for_reading(
28  CORE_RWLock_Control                 *the_rwlock,
29  Objects_Id                           id,
30  bool                                 wait,
31  Watchdog_Interval                    timeout,
32  CORE_RWLock_API_mp_support_callout   api_rwlock_mp_support
33)
34{
35  ISR_Level       level;
36  Thread_Control *executing = _Thread_Executing;
37
38  /*
39   *  If unlocked, then OK to read.
40   *  If locked for reading and no waiters, then OK to read.
41   *  If any thread is waiting, then we wait.
42   */
43
44  _ISR_Disable( level );
45    switch ( the_rwlock->current_state ) {
46      case CORE_RWLOCK_UNLOCKED:
47        the_rwlock->current_state = CORE_RWLOCK_LOCKED_FOR_READING;
48        the_rwlock->number_of_readers += 1;
49        _ISR_Enable( level );
50        executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL;
51        return;
52
53      case CORE_RWLOCK_LOCKED_FOR_READING: {
54        Thread_Control *waiter;
55        waiter = _Thread_queue_First( &the_rwlock->Wait_queue );
56        if ( !waiter ) {
57          the_rwlock->number_of_readers += 1;
58          _ISR_Enable( level );
59          executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL;
60          return;
61        }
62        break;
63      }
64      case CORE_RWLOCK_LOCKED_FOR_WRITING:
65        break;
66    }
67
68    /*
69     *  If the thread is not willing to wait, then return immediately.
70     */
71
72    if ( !wait ) {
73      _ISR_Enable( level );
74      executing->Wait.return_code = CORE_RWLOCK_UNAVAILABLE;
75      return;
76    }
77
78    /*
79     *  We need to wait to enter this critical section
80     */
81
82    _Thread_queue_Enter_critical_section( &the_rwlock->Wait_queue );
83    executing->Wait.queue       = &the_rwlock->Wait_queue;
84    executing->Wait.id          = id;
85    executing->Wait.option      = CORE_RWLOCK_THREAD_WAITING_FOR_READ;
86    executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL;
87    _ISR_Enable( level );
88
89    _Thread_queue_Enqueue_with_handler(
90       &the_rwlock->Wait_queue,
91       timeout,
92       _CORE_RWLock_Timeout
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.