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

4.104.114.95
Last change on this file since f8437c8 was f8437c8, checked in by Ralf Corsepius <ralf.corsepius@…>, on 09/04/08 at 15:23:12

Convert to "bool".

  • 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;
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  status = _POSIX_Absolute_timeout_to_ticks( abstime, &ticks );
62  switch (status) {
63    case POSIX_ABSOLUTE_TIMEOUT_INVALID:
64    case POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST:
65    case POSIX_ABSOLUTE_TIMEOUT_IS_NOW:
66      do_wait = FALSE;
67      break;
68    case POSIX_ABSOLUTE_TIMEOUT_IS_IN_FUTURE:
69      do_wait = TRUE;
70      break;
71  }
72
73  the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
74  switch ( location ) {
75
76    case OBJECTS_LOCAL:
77
78      _CORE_RWLock_Obtain_for_writing(
79        &the_rwlock->RWLock,
80        *rwlock,
81        do_wait,
82        ticks,
83        NULL
84      );
85
86      _Thread_Enable_dispatch();
87      if ( !do_wait &&
88           (_Thread_Executing->Wait.return_code == CORE_RWLOCK_UNAVAILABLE) ) {
89        switch (status) {
90          case POSIX_ABSOLUTE_TIMEOUT_INVALID:
91            return EINVAL;
92          case POSIX_ABSOLUTE_TIMEOUT_IS_IN_PAST:
93          case POSIX_ABSOLUTE_TIMEOUT_IS_NOW:
94            return ETIMEDOUT;
95          case POSIX_ABSOLUTE_TIMEOUT_IS_IN_FUTURE:
96            break;
97        }
98      }
99
100      return _POSIX_RWLock_Translate_core_RWLock_return_code(
101        (CORE_RWLock_Status) _Thread_Executing->Wait.return_code
102      );
103
104#if defined(RTEMS_MULTIPROCESSING)
105    case OBJECTS_REMOTE:
106#endif
107    case OBJECTS_ERROR:
108      break;
109  }
110
111  return EINVAL;
112}
Note: See TracBrowser for help on using the repository browser.