source: rtems/cpukit/posix/src/prwlockinit.c @ 22112254

4.8
Last change on this file since 22112254 was 22112254, checked in by Glenn Humphrey <glenn.humphrey@…>, on Nov 6, 2007 at 7:54:22 PM

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

Miscellaneous changes made after a review against the POSIX spec.

  • posix/src/pbarrierinit.c, posix/src/prwlockinit.c: If the caller passes a NULL in the attributes parameter, default attributes are used.
  • posix/src/prwlockdestroy.c: If there is at least one thread waiting, do not allow deletion.
  • posix/src/prwlockwrlock.c: Corrected parameter passed to the core operation used to obtain a RWLock for writing.
  • posix/src/pspinlocktranslatereturncode.c, score/include/rtems/score/corespinlock.h, score/src/corespinlockrelease.c: If the current thread is not the holder of the lock, do not allow an unlock and return EPERM.
  • score/src/corerwlockobtainwrite.c: Corrected to use the operation for queueing with a timeout handler.
  • Property mode set to 100644
File size: 2.3 KB
Line 
1/*
2 *  POSIX RWLock Manager -- Destroy a RWLock Instance
3 *
4 *  COPYRIGHT (c) 1989-2006.
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
24/*
25 *  pthread_rwlock_init
26 *
27 *  This directive creates a rwlock.  A rwlock id is returned.
28 *
29 *  Input parameters:
30 *    rwlock          - pointer to rwlock id
31 *    attr            - rwlock attributes
32 *
33 *  Output parameters:
34 *    rwlock     - rwlock id
35 *    0          - if successful
36 *    error code - if unsuccessful
37 */
38
39int pthread_rwlock_init(
40  pthread_rwlock_t           *rwlock,
41  const pthread_rwlockattr_t *attr
42)
43{
44  POSIX_RWLock_Control        *the_rwlock;
45  CORE_RWLock_Attributes       the_attributes;
46  pthread_rwlockattr_t         default_attr;
47  const pthread_rwlockattr_t  *the_attr;
48
49  /*
50   *  Error check parameters
51   */
52  if ( !rwlock )
53    return EINVAL;
54
55  /*
56   * If the user passed in NULL, use the default attributes
57   */
58  if ( attr ) {
59    the_attr = attr;
60  } else {
61    (void) pthread_rwlockattr_init( &default_attr );
62    the_attr = &default_attr;
63  }
64
65  /*
66   * Now start error checking the attributes that we are going to use
67   */
68  if ( !attr->is_initialized )
69    return EINVAL;
70
71  switch ( attr->process_shared ) {
72    case PTHREAD_PROCESS_PRIVATE:    /* only supported values */
73      break;
74    case PTHREAD_PROCESS_SHARED:
75    default:
76      return EINVAL;
77  }
78
79  /*
80   * Convert from POSIX attributes to Core RWLock attributes
81   */
82  /*  Currently there are no core rwlock attributes */
83
84  /*
85   * Enter dispatching critical section to allocate and initialize RWLock
86   */
87  _Thread_Disable_dispatch();             /* prevents deletion */
88
89  the_rwlock = _POSIX_RWLock_Allocate();
90
91  if ( !the_rwlock ) {
92    _Thread_Enable_dispatch();
93    return EAGAIN;
94  }
95
96  _CORE_RWLock_Initialize( &the_rwlock->RWLock, &the_attributes );
97
98  _Objects_Open(
99    &_POSIX_RWLock_Information,
100    &the_rwlock->Object,
101    0
102  );
103
104  *rwlock = the_rwlock->Object.id;
105
106  _Thread_Enable_dispatch();
107  return 0;
108}
Note: See TracBrowser for help on using the repository browser.