source: rtems/cpukit/posix/src/prwlocktimedwrlock.c @ 1d56a7a

4.104.114.9
Last change on this file since 1d56a7a was 1d56a7a, checked in by Glenn Humphrey <glenn.humphrey@…>, on Nov 27, 2007 at 6:38:18 PM

2007-11-27 Glenn Humphrey <glenn.humphrey@…>

  • posix/src/prwlocktimedrdlock.c, posix/src/prwlocktimedwrlock.c, rtems/include/rtems/rtems/barrier.h, score/src/corerwlockobtainread.c, score/src/corerwlockobtainwrite.c, score/src/corerwlockrelease.c: Fixed several implementation errors.
  • Property mode set to 100644
File size: 1.7 KB
Line 
1/*
2 *  POSIX RWLock Manager -- Attempt to Obtain a Write Lock on a RWLock Instance
3 *
4 *  COPYRIGHT (c) 1989-2007.
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  int                    status;
46  Watchdog_Interval      ticks;
47
48  if ( !rwlock )
49    return EINVAL;
50
51  status = _POSIX_Absolute_timeout_to_ticks( abstime, &ticks );
52  if ( status )
53    return status;
54
55  the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
56  switch ( location ) {
57
58#if defined(RTEMS_MULTIPROCESSING)
59    case OBJECTS_REMOTE:
60#endif
61    case OBJECTS_ERROR:
62      return EINVAL;
63
64    case OBJECTS_LOCAL:
65
66      _CORE_RWLock_Obtain_for_writing(
67        &the_rwlock->RWLock,
68        *rwlock,
69        TRUE,                 // we are willing to wait up to ticks
70        ticks,
71        NULL
72      );
73
74      _Thread_Enable_dispatch();
75      return _POSIX_RWLock_Translate_core_RWLock_return_code(
76        (CORE_RWLock_Status) _Thread_Executing->Wait.return_code
77      );
78  }
79
80  return POSIX_BOTTOM_REACHED();
81}
Note: See TracBrowser for help on using the repository browser.