source: rtems/cpukit/posix/src/prwlocktimedwrlock.c @ f23d470

5
Last change on this file since f23d470 was f23d470, checked in by Gedare Bloom <gedare@…>, on 06/09/16 at 15:33:15

cpukit: Add and use Watchdog_Discipline.

Clock disciplines may be WATCHDOG_RELATIVE, WATCHDOG_ABSOLUTE,
or WATCHDOG_NO_TIMEOUT. A discipline of WATCHDOG_RELATIVE with
a timeout of WATCHDOG_NO_TIMEOUT is equivalent to a discipline
of WATCHDOG_NO_TIMEOUT.

updates #2732

  • Property mode set to 100644
File size: 2.4 KB
Line 
1/**
2 * @file
3 *
4 * @brief Function applies a Write lock to RWLock referenced by rwlock
5 * @ingroup POSIXAPI
6 */
7
8/*
9 *  POSIX RWLock Manager -- Attempt to Obtain a Write Lock on a RWLock Instance
10 *
11 *  COPYRIGHT (c) 1989-2008.
12 *  On-Line Applications Research Corporation (OAR).
13 *
14 *  The license and distribution terms for this file may be
15 *  found in the file LICENSE in this distribution or at
16 *  http://www.rtems.org/license/LICENSE.
17 */
18
19#if HAVE_CONFIG_H
20#include "config.h"
21#endif
22
23#include <rtems/posix/rwlockimpl.h>
24#include <rtems/posix/posixapi.h>
25#include <rtems/score/todimpl.h>
26
27int pthread_rwlock_timedwrlock(
28  pthread_rwlock_t      *rwlock,
29  const struct timespec *abstime
30)
31{
32  POSIX_RWLock_Control                    *the_rwlock;
33  Thread_queue_Context                     queue_context;
34  Watchdog_Interval                        ticks;
35  bool                                     do_wait;
36  TOD_Absolute_timeout_conversion_results  timeout_status;
37  Status_Control                           status;
38
39  /*
40   *  POSIX requires that blocking calls with timeouts that take
41   *  an absolute timeout must ignore issues with the absolute
42   *  time provided if the operation would otherwise succeed.
43   *  So we check the abstime provided, and hold on to whether it
44   *  is valid or not.  If it isn't correct and in the future,
45   *  then we do a polling operation and convert the STATUS_UNAVAILABLE
46   *  status into the appropriate error.
47   *
48   *  If the timeout status is TOD_ABSOLUTE_TIMEOUT_INVALID,
49   *  TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST, or TOD_ABSOLUTE_TIMEOUT_IS_NOW,
50   *  then we should not wait.
51   */
52  timeout_status = _TOD_Absolute_timeout_to_ticks( abstime, &ticks );
53  do_wait = ( timeout_status == TOD_ABSOLUTE_TIMEOUT_IS_IN_FUTURE );
54
55  the_rwlock = _POSIX_RWLock_Get( rwlock, &queue_context );
56
57  if ( the_rwlock == NULL ) {
58    return EINVAL;
59  }
60
61  _Thread_queue_Context_set_relative_timeout( &queue_context, ticks );
62  status = _CORE_RWLock_Seize_for_writing(
63    &the_rwlock->RWLock,
64    _Thread_Executing,
65    do_wait,
66    &queue_context
67  );
68
69  if ( !do_wait && status == STATUS_UNAVAILABLE ) {
70    if ( timeout_status == TOD_ABSOLUTE_TIMEOUT_INVALID ) {
71      return EINVAL;
72    }
73
74    if (
75      timeout_status == TOD_ABSOLUTE_TIMEOUT_IS_IN_PAST
76        || timeout_status == TOD_ABSOLUTE_TIMEOUT_IS_NOW
77    ) {
78      return ETIMEDOUT;
79    }
80  }
81
82  return _POSIX_Get_error( status );
83}
Note: See TracBrowser for help on using the repository browser.