source: rtems/cpukit/posix/src/prwlockwrlock.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 Obtain a Write Lock on a RWlock Instance
5 * @ingroup POSIXAPI
6 */
7
8/*
9 *  POSIX RWLock Manager -- Obtain a Write Lock on a RWLock Instance
10 *
11 *  COPYRIGHT (c) 1989-2007.
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 <pthread.h>
24#include <errno.h>
25
26#include <rtems/posix/rwlockimpl.h>
27#include <rtems/score/thread.h>
28
29/*
30 *  pthread_rwlock_wrlock
31 *
32 *  This directive attempts to obtain a write only lock on an rwlock instance.
33 *
34 *  Input parameters:
35 *    rwlock          - pointer to rwlock id
36 *
37 *  Output parameters:
38 *    0          - if successful
39 *    error code - if unsuccessful
40 */
41
42int pthread_rwlock_wrlock(
43  pthread_rwlock_t  *rwlock
44)
45{
46  POSIX_RWLock_Control  *the_rwlock;
47  Objects_Locations      location;
48  Thread_Control        *executing;
49
50  the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
51  switch ( location ) {
52
53    case OBJECTS_LOCAL:
54
55      executing = _Thread_Executing;
56      _CORE_RWLock_Obtain_for_writing(
57        &the_rwlock->RWLock,
58        executing,
59        *rwlock,
60        true,          /* do not timeout -- wait forever */
61        0,
62        NULL
63      );
64
65      _Objects_Put( &the_rwlock->Object );
66      return _POSIX_RWLock_Translate_core_RWLock_return_code(
67        (CORE_RWLock_Status) executing->Wait.return_code
68      );
69
70#if defined(RTEMS_MULTIPROCESSING)
71    case OBJECTS_REMOTE:
72#endif
73    case OBJECTS_ERROR:
74      break;
75  }
76
77  return EINVAL;
78}
Note: See TracBrowser for help on using the repository browser.