source: rtems/cpukit/posix/src/prwlockdestroy.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.8 KB
Line 
1/**
2 *  @file
3 *
4 *  @brief Destroy a RWLock
5 *  @ingroup POSIXAPI
6 */
7/*
8 *  COPYRIGHT (c) 1989-2007.
9 *  On-Line Applications Research Corporation (OAR).
10 *
11 *  The license and distribution terms for this file may be
12 *  found in the file LICENSE in this distribution or at
13 *  http://www.rtems.org/license/LICENSE.
14 */
15
16#if HAVE_CONFIG_H
17#include "config.h"
18#endif
19
20#include <pthread.h>
21#include <errno.h>
22
23#include <rtems/posix/rwlockimpl.h>
24#include <rtems/score/threadqimpl.h>
25
26/**
27 *  This directive allows a thread to delete a rwlock specified by
28 *  the rwlock id.  The rwlock is freed back to the inactive
29 *  rwlock chain.
30 *
31 *  @param[in] rwlock is the rwlock id
32 *
33 *  @return This method returns 0 if there was not an
34 *  error. Otherwise, a status code is returned indicating the
35 *  source of the error.
36 */
37int pthread_rwlock_destroy(
38  pthread_rwlock_t *rwlock
39)
40{
41  POSIX_RWLock_Control *the_rwlock = NULL;
42  Objects_Locations      location;
43
44  _Objects_Allocator_lock();
45  the_rwlock = _POSIX_RWLock_Get( rwlock, &location );
46  switch ( location ) {
47
48    case OBJECTS_LOCAL:
49      /*
50       *  If there is at least one thread waiting, then do not delete it.
51       */
52      if ( _Thread_queue_First( &the_rwlock->RWLock.Wait_queue ) != NULL ) {
53        _Objects_Put( &the_rwlock->Object );
54        _Objects_Allocator_unlock();
55        return EBUSY;
56      }
57
58      /*
59       *  POSIX doesn't require behavior when it is locked.
60       */
61
62      _Objects_Close( &_POSIX_RWLock_Information, &the_rwlock->Object );
63      _Objects_Put( &the_rwlock->Object );
64      _POSIX_RWLock_Free( the_rwlock );
65      _Objects_Allocator_unlock();
66
67      return 0;
68
69#if defined(RTEMS_MULTIPROCESSING)
70    case OBJECTS_REMOTE:
71#endif
72    case OBJECTS_ERROR:
73      break;
74  }
75
76  _Objects_Allocator_unlock();
77
78  return EINVAL;
79}
Note: See TracBrowser for help on using the repository browser.