source: rtems/cpukit/posix/src/prwlocktrywrlock.c @ b9f95225

4.115
Last change on this file since b9f95225 was b9f95225, checked in by Sebastian Huber <sebastian.huber@…>, on 10/08/14 at 08:31:36

posix: Add auto initializaton for rwlock

  • Property mode set to 100644
File size: 1.6 KB
Line 
1/**
2 * @file
3 *
4 * @brief Attempt to Obtain a Write Lock on a RWLock Instance
5 * @ingroup POSIXAPI
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2007.
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.org/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/posix/rwlockimpl.h>
25#include <rtems/score/thread.h>
26
27/*
28 *  pthread_rwlock_trywrlock
29 *
30 *  This directive attempts to obtain a Write only lock on an rwlock instance.
31 *
32 *  Input parameters:
33 *    rwlock          - pointer to rwlock id
34 *
35 *  Output parameters:
36 *    0          - if successful
37 *    error code - if unsuccessful
38 */
39
40int pthread_rwlock_trywrlock(
41  pthread_rwlock_t  *rwlock
42)
43{
44  POSIX_RWLock_Control  *the_rwlock;
45  Objects_Locations      location;
46  Thread_Control        *executing;
47
48  the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
49  switch ( location ) {
50
51    case OBJECTS_LOCAL:
52
53      executing = _Thread_Executing;
54      _CORE_RWLock_Obtain_for_writing(
55        &the_rwlock->RWLock,
56        executing,
57        *rwlock,
58        false,                 /* we are not willing to wait */
59        0,
60        NULL
61      );
62
63      _Objects_Put( &the_rwlock->Object );
64      return _POSIX_RWLock_Translate_core_RWLock_return_code(
65        (CORE_RWLock_Status) executing->Wait.return_code
66      );
67
68#if defined(RTEMS_MULTIPROCESSING)
69    case OBJECTS_REMOTE:
70#endif
71    case OBJECTS_ERROR:
72      break;
73  }
74
75  return EINVAL;
76}
Note: See TracBrowser for help on using the repository browser.