source: rtems/cpukit/posix/src/mutexdestroy.c @ 48b04fc3

5
Last change on this file since 48b04fc3 was 48b04fc3, checked in by Sebastian Huber <sebastian.huber@…>, on Apr 19, 2016 at 4:28:03 AM

posix: Avoid Giant lock for mutexes

Delete _POSIX_Mutex_Get(). Use _POSIX_Mutex_Get_interrupt_disable()
instead.

Update #2555.

  • Property mode set to 100644
File size: 1.4 KB
Line 
1/**
2 * @file
3 *
4 * @brief Initializing and Destroying a Mutex
5 * @ingroup POSIXAPI
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2007.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/posix/muteximpl.h>
22
23/*
24 *  11.3.2 Initializing and Destroying a Mutex, P1003.1c/Draft 10, p. 87
25 */
26
27int pthread_mutex_destroy(
28  pthread_mutex_t           *mutex
29)
30{
31  POSIX_Mutex_Control *the_mutex;
32  ISR_lock_Context     lock_context;
33  int                  eno;
34
35  _Objects_Allocator_lock();
36
37  the_mutex = _POSIX_Mutex_Get_interrupt_disable( mutex, &lock_context );
38
39  if ( the_mutex != NULL ) {
40    _CORE_mutex_Acquire_critical( &the_mutex->Mutex, &lock_context );
41
42    /*
43     * XXX: There is an error for the mutex being locked
44     *  or being in use by a condition variable.
45     */
46
47    if ( !_CORE_mutex_Is_locked( &the_mutex->Mutex ) ) {
48      _Objects_Close( &_POSIX_Mutex_Information, &the_mutex->Object );
49      _CORE_mutex_Release( &the_mutex->Mutex, &lock_context );
50      _CORE_mutex_Destroy( &the_mutex->Mutex );
51      _POSIX_Mutex_Free( the_mutex );
52      eno = 0;
53    } else {
54      _CORE_mutex_Release( &the_mutex->Mutex, &lock_context );
55      eno = EBUSY;
56    }
57  } else {
58    eno = EINVAL;
59  }
60
61  _Objects_Allocator_unlock();
62  return eno;
63}
Note: See TracBrowser for help on using the repository browser.