source: rtems/cpukit/posix/src/prwlocktimedrdlock.c @ 89fc9345

5
Last change on this file since 89fc9345 was 89fc9345, checked in by Sebastian Huber <sebastian.huber@…>, on 09/21/17 at 13:42:45

posix: Implement self-contained POSIX rwlocks

POSIX rwlocks are now available in all configurations and no longer
depend on --enable-posix.

Update #2514.
Update #3115.

  • Property mode set to 100644
File size: 2.3 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, CLOCK_REALTIME, &ticks );
51  do_wait = ( timeout_status == TOD_ABSOLUTE_TIMEOUT_IS_IN_FUTURE );
52
53  the_rwlock = _POSIX_RWLock_Get( rwlock );
54  POSIX_RWLOCK_VALIDATE_OBJECT( the_rwlock );
55
56  _Thread_queue_Context_initialize( &queue_context );
57  _Thread_queue_Context_set_relative_timeout( &queue_context, ticks );
58  status = _CORE_RWLock_Seize_for_reading(
59    &the_rwlock->RWLock,
60    do_wait,
61    &queue_context
62  );
63
64  if ( !do_wait && status == STATUS_UNAVAILABLE ) {
65    if ( timeout_status == TOD_ABSOLUTE_TIMEOUT_INVALID ) {
66      return EINVAL;
67    }
68
69    if (
70      timeout_status == TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST
71        || timeout_status == TOD_ABSOLUTE_TIMEOUT_IS_NOW
72    ) {
73      return ETIMEDOUT;
74    }
75  }
76
77  return _POSIX_Get_error( status );
78}
Note: See TracBrowser for help on using the repository browser.