source: rtems/cpukit/posix/src/prwlockwrlock.c @ be1b8a7

4.115
Last change on this file since be1b8a7 was 982e9746, checked in by Sebastian Huber <sebastian.huber@…>, on 07/19/13 at 13:00:11

score: Avoid direct usage of _Thread_Executing

Pass the executing thread as a function parameter. Obtain the executing
thread inside a thread dispatch critical section to avoid problems on
SMP.

  • Property mode set to 100644
File size: 1.7 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.com/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/system.h>
27#include <rtems/posix/rwlockimpl.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  if ( !rwlock )
51    return EINVAL;
52
53  the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
54  switch ( location ) {
55
56    case OBJECTS_LOCAL:
57
58      executing = _Thread_Executing;
59      _CORE_RWLock_Obtain_for_writing(
60        &the_rwlock->RWLock,
61        executing,
62        *rwlock,
63        true,          /* do not timeout -- wait forever */
64        0,
65        NULL
66      );
67
68      _Objects_Put( &the_rwlock->Object );
69      return _POSIX_RWLock_Translate_core_RWLock_return_code(
70        (CORE_RWLock_Status) executing->Wait.return_code
71      );
72
73#if defined(RTEMS_MULTIPROCESSING)
74    case OBJECTS_REMOTE:
75#endif
76    case OBJECTS_ERROR:
77      break;
78  }
79
80  return EINVAL;
81}
Note: See TracBrowser for help on using the repository browser.