source: rtems/cpukit/posix/src/prwlocktimedrdlock.c @ 5cb175bb

4.115
Last change on this file since 5cb175bb was 5cb175bb, checked in by Joel Sherrill <joel.sherrill@…>, on 01/10/13 at 19:22:31

cpukit/posix: Doxygen group is POSIXAPI

  • Property mode set to 100644
File size: 2.8 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.com/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <pthread.h>
22#include <errno.h>
23
24#include <rtems/system.h>
25#include <rtems/posix/rwlock.h>
26#include <rtems/posix/time.h>
27
28/*
29 *  pthread_rwlock_timedrdlock
30 *
31 *  This directive attempts to obtain a read only lock on an rwlock instance.
32 *
33 *  Input parameters:
34 *    rwlock          - pointer to rwlock id
35 *
36 *  Output parameters:
37 *    0          - if successful
38 *    error code - if unsuccessful
39 */
40
41int pthread_rwlock_timedrdlock(
42  pthread_rwlock_t      *rwlock,
43  const struct timespec *abstime
44)
45{
46  POSIX_RWLock_Control                        *the_rwlock;
47  Objects_Locations                            location;
48  Watchdog_Interval                            ticks;
49  bool                                         do_wait = true;
50  POSIX_Absolute_timeout_conversion_results_t  status;
51
52  if ( !rwlock )
53    return EINVAL;
54
55  /*
56   *  POSIX requires that blocking calls with timeouts that take
57   *  an absolute timeout must ignore issues with the absolute
58   *  time provided if the operation would otherwise succeed.
59   *  So we check the abstime provided, and hold on to whether it
60   *  is valid or not.  If it isn't correct and in the future,
61   *  then we do a polling operation and convert the UNSATISFIED
62   *  status into the appropriate error.
63   *
64   *  If the status is POSIX_ABSOLUTE_TIMEOUT_INVALID,
65   *  POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST, or POSIX_ABSOLUTE_TIMEOUT_IS_NOW,
66   *  then we should not wait.
67   */
68  status = _POSIX_Absolute_timeout_to_ticks( abstime, &ticks );
69  if ( status != POSIX_ABSOLUTE_TIMEOUT_IS_IN_FUTURE )
70    do_wait = false;
71
72  the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
73  switch ( location ) {
74
75    case OBJECTS_LOCAL:
76
77      _CORE_RWLock_Obtain_for_reading(
78        &the_rwlock->RWLock,
79        *rwlock,
80        do_wait,
81        ticks,
82        NULL
83      );
84
85      _Thread_Enable_dispatch();
86      if ( !do_wait ) {
87        if ( _Thread_Executing->Wait.return_code == CORE_RWLOCK_UNAVAILABLE ) {
88          if ( status == POSIX_ABSOLUTE_TIMEOUT_INVALID )
89            return EINVAL;
90          if ( status == POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST ||
91               status == POSIX_ABSOLUTE_TIMEOUT_IS_NOW )
92            return ETIMEDOUT;
93        }
94      }
95
96      return _POSIX_RWLock_Translate_core_RWLock_return_code(
97        (CORE_RWLock_Status) _Thread_Executing->Wait.return_code
98      );
99
100#if defined(RTEMS_MULTIPROCESSING)
101    case OBJECTS_REMOTE:
102#endif
103    case OBJECTS_ERROR:
104      break;
105  }
106
107  return EINVAL;
108}
Note: See TracBrowser for help on using the repository browser.