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

Last change on this file was 380fb9f, checked in by Joel Sherrill <joel@…>, on 02/16/22 at 22:32:05

cpukit/posix/src/[p-z]*.c: Change license to BSD-2

Updates #3053.

  • Property mode set to 100644
File size: 3.0 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup POSIXAPI
7 *
8 * @brief Allocate resources to use the read-write lock and Initialize it
9 */
10
11/*
12 *  POSIX RWLock Manager -- Destroy a RWLock Instance
13 *
14 *  COPYRIGHT (c) 1989-2006.
15 *  On-Line Applications Research Corporation (OAR).
16 *
17 * Redistribution and use in source and binary forms, with or without
18 * modification, are permitted provided that the following conditions
19 * are met:
20 * 1. Redistributions of source code must retain the above copyright
21 *    notice, this list of conditions and the following disclaimer.
22 * 2. Redistributions in binary form must reproduce the above copyright
23 *    notice, this list of conditions and the following disclaimer in the
24 *    documentation and/or other materials provided with the distribution.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
27 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
30 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39#ifdef HAVE_CONFIG_H
40#include "config.h"
41#endif
42
43#include <rtems/posix/rwlockimpl.h>
44#include <rtems/posix/posixapi.h>
45
46RTEMS_STATIC_ASSERT(
47  offsetof( POSIX_RWLock_Control, flags )
48    == offsetof( pthread_rwlock_t, _flags ),
49  POSIX_RWLOCK_CONTROL_FLAGS
50);
51
52RTEMS_STATIC_ASSERT(
53  offsetof( POSIX_RWLock_Control, RWLock.current_state )
54    == offsetof( pthread_rwlock_t, _current_state ),
55  POSIX_RWLOCK_CONTROL_CURRENT_STATE
56);
57
58RTEMS_STATIC_ASSERT(
59  offsetof( POSIX_RWLock_Control, RWLock.number_of_readers )
60    == offsetof( pthread_rwlock_t, _number_of_readers ),
61  POSIX_RWLOCK_CONTROL_NUMBER_OF_READERS
62);
63
64RTEMS_STATIC_ASSERT(
65  offsetof( POSIX_RWLock_Control, RWLock.Queue )
66    == offsetof( pthread_rwlock_t, _Queue ),
67  POSIX_RWLOCK_CONTROL_QUEUE
68);
69
70RTEMS_STATIC_ASSERT(
71  sizeof( POSIX_RWLock_Control ) == sizeof( pthread_rwlock_t ),
72  POSIX_RWLOCK_CONTROL_SIZE
73);
74
75int pthread_rwlock_init(
76  pthread_rwlock_t           *rwlock,
77  const pthread_rwlockattr_t *attr
78)
79{
80  POSIX_RWLock_Control *the_rwlock;
81
82  the_rwlock = _POSIX_RWLock_Get( rwlock );
83
84  if ( the_rwlock == NULL ) {
85    return EINVAL;
86  }
87
88  if ( attr != NULL ) {
89    if ( !attr->is_initialized ) {
90      return EINVAL;
91    }
92
93    if ( !_POSIX_Is_valid_pshared( attr->process_shared ) ) {
94      return EINVAL;
95    }
96  }
97
98  the_rwlock->flags = (uintptr_t) the_rwlock ^ POSIX_RWLOCK_MAGIC;
99  _CORE_RWLock_Initialize( &the_rwlock->RWLock );
100  return 0;
101}
Note: See TracBrowser for help on using the repository browser.