source: rtems/cpukit/score/src/corerwlockobtainread.c @ 1e1a91ed

5
Last change on this file since 1e1a91ed was 1e1a91ed, checked in by Sebastian Huber <sebastian.huber@…>, on 03/23/16 at 09:01:31

score: Remove Thread_queue_Queue::operations field

Remove the Thread_queue_Queue::operations field to reduce the size of
this structure. Add a thread queue operations parameter to the
_Thread_queue_First(), _Thread_queue_First_locked(),
_Thread_queue_Enqueue(), _Thread_queue_Dequeue() and
_Thread_queue_Flush() functions. This is a preparation patch to reduce
the size of several synchronization objects.

  • Property mode set to 100644
File size: 2.7 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.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/score/corerwlockimpl.h>
22#include <rtems/score/threadqimpl.h>
23#include <rtems/score/statesimpl.h>
24#include <rtems/score/watchdog.h>
25
26void _CORE_RWLock_Obtain_for_reading(
27  CORE_RWLock_Control                 *the_rwlock,
28  Thread_Control                      *executing,
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_lock_Context lock_context;
36
37  /*
38   *  If unlocked, then OK to read.
39   *  If locked for reading and no waiters, then OK to read.
40   *  If any thread is waiting, then we wait.
41   */
42
43  _Thread_queue_Acquire( &the_rwlock->Wait_queue, &lock_context );
44    switch ( the_rwlock->current_state ) {
45      case CORE_RWLOCK_UNLOCKED:
46        the_rwlock->current_state = CORE_RWLOCK_LOCKED_FOR_READING;
47        the_rwlock->number_of_readers += 1;
48        _Thread_queue_Release( &the_rwlock->Wait_queue, &lock_context );
49        executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL;
50        return;
51
52      case CORE_RWLOCK_LOCKED_FOR_READING: {
53        Thread_Control *waiter;
54        waiter = _Thread_queue_First_locked(
55          &the_rwlock->Wait_queue,
56          CORE_RWLOCK_TQ_OPERATIONS
57        );
58        if ( !waiter ) {
59          the_rwlock->number_of_readers += 1;
60          _Thread_queue_Release( &the_rwlock->Wait_queue, &lock_context );
61          executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL;
62          return;
63        }
64        break;
65      }
66      case CORE_RWLOCK_LOCKED_FOR_WRITING:
67        break;
68    }
69
70    /*
71     *  If the thread is not willing to wait, then return immediately.
72     */
73
74    if ( !wait ) {
75      _Thread_queue_Release( &the_rwlock->Wait_queue, &lock_context );
76      executing->Wait.return_code = CORE_RWLOCK_UNAVAILABLE;
77      return;
78    }
79
80    /*
81     *  We need to wait to enter this critical section
82     */
83
84    executing->Wait.id          = id;
85    executing->Wait.option      = CORE_RWLOCK_THREAD_WAITING_FOR_READ;
86    executing->Wait.return_code = CORE_RWLOCK_SUCCESSFUL;
87
88    _Thread_queue_Enqueue_critical(
89       &the_rwlock->Wait_queue.Queue,
90       CORE_RWLOCK_TQ_OPERATIONS,
91       executing,
92       STATES_WAITING_FOR_RWLOCK,
93       timeout,
94       CORE_RWLOCK_TIMEOUT,
95       &lock_context
96    );
97
98    /* return to API level so it can dispatch and we block */
99}
Note: See TracBrowser for help on using the repository browser.