source: rtems/cpukit/posix/src/prwlocktimedwrlock.c @ 8f6b7b51

4.104.115
Last change on this file since 8f6b7b51 was 6805ac37, checked in by Joel Sherrill <joel.sherrill@…>, on 10/10/09 at 15:21:41

2009-10-10 Joel Sherrill <joel.sherrill@…>

  • posix/src/mqueuetimedreceive.c, posix/src/mqueuetimedsend.c, posix/src/mutextimedlock.c, posix/src/prwlocktimedrdlock.c, posix/src/prwlocktimedwrlock.c, posix/src/semtimedwait.c: Switch from switch to if's because only one value needed to be tested. This shrinks the code and makes it easier to do coverage analysis on.
  • Property mode set to 100644
File size: 2.8 KB
Line 
1/*
2 *  POSIX RWLock Manager -- Attempt to Obtain a Write Lock on a RWLock Instance
3 *
4 *  COPYRIGHT (c) 1989-2008.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 *
11 *  $Id$
12 */
13
14#if HAVE_CONFIG_H
15#include "config.h"
16#endif
17
18#include <pthread.h>
19#include <errno.h>
20
21#include <rtems/system.h>
22#include <rtems/posix/rwlock.h>
23#include <rtems/posix/time.h>
24
25/*
26 *  pthread_rwlock_timedwrlock
27 *
28 *  This directive attempts to obtain a write only lock on an rwlock instance.
29 *
30 *  Input parameters:
31 *    rwlock          - pointer to rwlock id
32 *
33 *  Output parameters:
34 *    0          - if successful
35 *    error code - if unsuccessful
36 */
37
38int pthread_rwlock_timedwrlock(
39  pthread_rwlock_t      *rwlock,
40  const struct timespec *abstime
41)
42{
43  POSIX_RWLock_Control                        *the_rwlock;
44  Objects_Locations                            location;
45  Watchdog_Interval                            ticks;
46  bool                                         do_wait = true;
47  POSIX_Absolute_timeout_conversion_results_t  status;
48 
49  if ( !rwlock )
50    return EINVAL;
51
52  /*
53   *  POSIX requires that blocking calls with timeouts that take
54   *  an absolute timeout must ignore issues with the absolute
55   *  time provided if the operation would otherwise succeed.
56   *  So we check the abstime provided, and hold on to whether it
57   *  is valid or not.  If it isn't correct and in the future,
58   *  then we do a polling operation and convert the UNSATISFIED
59   *  status into the appropriate error.
60   *
61   *  If the status is POSIX_ABSOLUTE_TIMEOUT_INVALID,
62   *  POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST, or POSIX_ABSOLUTE_TIMEOUT_IS_NOW,
63   *  then we should not wait.
64   */
65  status = _POSIX_Absolute_timeout_to_ticks( abstime, &ticks );
66  if ( status != POSIX_ABSOLUTE_TIMEOUT_IS_IN_FUTURE )
67    do_wait = false;
68
69  the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
70  switch ( location ) {
71
72    case OBJECTS_LOCAL:
73
74      _CORE_RWLock_Obtain_for_writing(
75        &the_rwlock->RWLock,
76        *rwlock,
77        do_wait,
78        ticks,
79        NULL
80      );
81
82      _Thread_Enable_dispatch();
83      if ( !do_wait &&
84           (_Thread_Executing->Wait.return_code == CORE_RWLOCK_UNAVAILABLE) ) {
85        switch (status) {
86          case POSIX_ABSOLUTE_TIMEOUT_INVALID:
87            return EINVAL;
88          case POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST:
89          case POSIX_ABSOLUTE_TIMEOUT_IS_NOW:
90            return ETIMEDOUT;
91          case POSIX_ABSOLUTE_TIMEOUT_IS_IN_FUTURE:
92            break;
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.