source: rtems/cpukit/posix/src/prwlocktimedrdlock.c @ dce48791

5
Last change on this file since dce48791 was dce48791, checked in by Sebastian Huber <sebastian.huber@…>, on 05/23/16 at 11:37:59

score: Add Status_Control for all APIs

Unify the status codes of the Classic and POSIX API to use the new enum
Status_Control. This eliminates the Thread_Control::Wait::timeout_code
field and the timeout parameter of _Thread_queue_Enqueue_critical() and
_MPCI_Send_request_packet(). It gets rid of the status code translation
tables and instead uses simple bit operations to get the status for a
particular API. This enables translation of status code constants at
compile time. Add _Thread_Wait_get_status() to avoid direct access of
thread internal data structures.

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/**
2 * @file
3 *
4 * @brief Attempt to Obtain a Read Lock on a RWLock Instance
5 * @ingroup POSIXAPI
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2008.
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/posix/rwlockimpl.h>
22#include <rtems/posix/posixapi.h>
23#include <rtems/score/todimpl.h>
24
25int pthread_rwlock_timedrdlock(
26  pthread_rwlock_t      *rwlock,
27  const struct timespec *abstime
28)
29{
30  POSIX_RWLock_Control                    *the_rwlock;
31  Thread_queue_Context                     queue_context;
32  Watchdog_Interval                        ticks;
33  bool                                     do_wait;
34  TOD_Absolute_timeout_conversion_results  timeout_status;
35  Status_Control                           status;
36
37  /*
38   *  POSIX requires that blocking calls with timeouts that take
39   *  an absolute timeout must ignore issues with the absolute
40   *  time provided if the operation would otherwise succeed.
41   *  So we check the abstime provided, and hold on to whether it
42   *  is valid or not.  If it isn't correct and in the future,
43   *  then we do a polling operation and convert the STATUS_UNAVAILABLE
44   *  status into the appropriate error.
45   *
46   *  If the timeout status is TOD_ABSOLUTE_TIMEOUT_INVALID,
47   *  TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST, or TOD_ABSOLUTE_TIMEOUT_IS_NOW,
48   *  then we should not wait.
49   */
50  timeout_status = _TOD_Absolute_timeout_to_ticks( abstime, &ticks );
51  do_wait = ( timeout_status == TOD_ABSOLUTE_TIMEOUT_IS_IN_FUTURE );
52
53  the_rwlock = _POSIX_RWLock_Get( rwlock, &queue_context );
54
55  if ( the_rwlock == NULL ) {
56    return EINVAL;
57  }
58
59  status = _CORE_RWLock_Seize_for_reading(
60    &the_rwlock->RWLock,
61    _Thread_Executing,
62    do_wait,
63    ticks,
64    &queue_context
65  );
66
67  if ( !do_wait && status == STATUS_UNAVAILABLE ) {
68    if ( timeout_status == TOD_ABSOLUTE_TIMEOUT_INVALID ) {
69      return EINVAL;
70    }
71
72    if (
73      timeout_status == TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST
74        || timeout_status == TOD_ABSOLUTE_TIMEOUT_IS_NOW
75    ) {
76      return ETIMEDOUT;
77    }
78  }
79
80  return _POSIX_Get_error( status );
81}
Note: See TracBrowser for help on using the repository browser.