source: rtems/cpukit/score/src/corerwlockobtainwrite.c @ 1666ffe5

5
Last change on this file since 1666ffe5 was 1666ffe5, checked in by Sebastian Huber <sebastian.huber@…>, on 10/19/17 at 12:17:31

score: Rename function threadq support function

Rename _Thread_queue_Context_set_do_nothing_enqueue_callout() into
_Thread_queue_Context_set_enqueue_do_nothing_extra(). More
_Thread_queue_Context_set_enqueue_*() functions will follow.

Update #3117.
Update #3182.

  • Property mode set to 100644
File size: 1.9 KB
Line 
1/**
2 * @file
3 *
4 * @brief RWLock Obtain for Writing
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/threadimpl.h>
23#include <rtems/score/threadqimpl.h>
24#include <rtems/score/statesimpl.h>
25#include <rtems/score/watchdog.h>
26
27Status_Control _CORE_RWLock_Seize_for_writing(
28  CORE_RWLock_Control  *the_rwlock,
29  bool                  wait,
30  Thread_queue_Context *queue_context
31)
32{
33  Thread_Control *executing;
34
35  /*
36   *  If unlocked, then OK to read.
37   *  Otherwise, we have to block.
38   *  If locked for reading and no waiters, then OK to read.
39   *  If any thread is waiting, then we wait.
40   */
41
42  executing = _CORE_RWLock_Acquire( the_rwlock, queue_context );
43
44  switch ( the_rwlock->current_state ) {
45    case CORE_RWLOCK_UNLOCKED:
46      the_rwlock->current_state = CORE_RWLOCK_LOCKED_FOR_WRITING;
47      _CORE_RWLock_Release( the_rwlock, queue_context );
48      return STATUS_SUCCESSFUL;
49
50    case CORE_RWLOCK_LOCKED_FOR_READING:
51    case CORE_RWLOCK_LOCKED_FOR_WRITING:
52      break;
53  }
54
55  /*
56   *  If the thread is not willing to wait, then return immediately.
57   */
58
59  if ( !wait ) {
60    _CORE_RWLock_Release( the_rwlock, queue_context );
61    return STATUS_UNAVAILABLE;
62  }
63
64  /*
65   *  We need to wait to enter this critical section
66   */
67
68  executing->Wait.option = CORE_RWLOCK_THREAD_WAITING_FOR_WRITE;
69
70  _Thread_queue_Context_set_thread_state(
71    queue_context,
72    STATES_WAITING_FOR_RWLOCK
73  );
74  _Thread_queue_Context_set_enqueue_do_nothing_extra( queue_context );
75  _Thread_queue_Enqueue(
76     &the_rwlock->Queue.Queue,
77     CORE_RWLOCK_TQ_OPERATIONS,
78     executing,
79     queue_context
80  );
81  return _Thread_Wait_get_status( executing );
82}
Note: See TracBrowser for help on using the repository browser.