source: rtems/cpukit/posix/src/prwlockinit.c @ 23fec9f0

4.115
Last change on this file since 23fec9f0 was 23fec9f0, checked in by Sebastian Huber <sebastian.huber@…>, on 03/27/14 at 13:16:12

score: PR2152: Use allocator mutex for objects

Use allocator mutex for objects allocate/free. This prevents that the
thread dispatch latency depends on the workspace/heap fragmentation.

  • Property mode set to 100644
File size: 2.3 KB
Line 
1/**
2 * @file
3 *
4 * @brief Allocate resources to use the read-write lock and Initialize it
5 * @ingroup POSIXAPI
6 */
7
8/*
9 *  POSIX RWLock Manager -- Destroy a RWLock Instance
10 *
11 *  COPYRIGHT (c) 1989-2006.
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/system.h>
27#include <rtems/posix/rwlockimpl.h>
28
29/*
30 *  pthread_rwlock_init
31 *
32 *  This directive creates a rwlock.  A rwlock id is returned.
33 *
34 *  Input parameters:
35 *    rwlock          - pointer to rwlock id
36 *    attr            - rwlock attributes
37 *
38 *  Output parameters:
39 *    rwlock     - rwlock id
40 *    0          - if successful
41 *    error code - if unsuccessful
42 */
43
44int pthread_rwlock_init(
45  pthread_rwlock_t           *rwlock,
46  const pthread_rwlockattr_t *attr
47)
48{
49  POSIX_RWLock_Control        *the_rwlock;
50  CORE_RWLock_Attributes       the_attributes;
51  pthread_rwlockattr_t         default_attr;
52  const pthread_rwlockattr_t  *the_attr;
53
54  /*
55   *  Error check parameters
56   */
57  if ( !rwlock )
58    return EINVAL;
59
60  /*
61   * If the user passed in NULL, use the default attributes
62   */
63  if ( attr ) {
64    the_attr = attr;
65  } else {
66    (void) pthread_rwlockattr_init( &default_attr );
67    the_attr = &default_attr;
68  }
69
70  /*
71   * Now start error checking the attributes that we are going to use
72   */
73  if ( !the_attr->is_initialized )
74    return EINVAL;
75
76  switch ( the_attr->process_shared ) {
77    case PTHREAD_PROCESS_PRIVATE:    /* only supported values */
78      break;
79    case PTHREAD_PROCESS_SHARED:
80    default:
81      return EINVAL;
82  }
83
84  /*
85   * Convert from POSIX attributes to Core RWLock attributes
86   *
87   * NOTE: Currently there are no core rwlock attributes
88   */
89  _CORE_RWLock_Initialize_attributes( &the_attributes );
90
91  the_rwlock = _POSIX_RWLock_Allocate();
92
93  if ( !the_rwlock ) {
94    _Objects_Allocator_unlock();
95    return EAGAIN;
96  }
97
98  _CORE_RWLock_Initialize( &the_rwlock->RWLock, &the_attributes );
99
100  _Objects_Open_u32(
101    &_POSIX_RWLock_Information,
102    &the_rwlock->Object,
103    0
104  );
105
106  *rwlock = the_rwlock->Object.id;
107
108  _Objects_Allocator_unlock();
109  return 0;
110}
Note: See TracBrowser for help on using the repository browser.