source: rtems/cpukit/posix/src/mutexget.c @ b8bdced1

5
Last change on this file since b8bdced1 was b8bdced1, checked in by Sebastian Huber <sebastian.huber@…>, on Apr 18, 2016 at 3:21:43 PM

posix: Simplify _POSIX_Mutex_Get_interrupt_disable

Remove superfluous location parameter.

  • Property mode set to 100644
File size: 1.7 KB
Line 
1/**
2 * @file
3 *
4 * @brief Convert POSIX Mutex ID to local object pointer
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#include <rtems/score/apimutex.h>
23
24static bool _POSIX_Mutex_Check_id_and_auto_init(
25  pthread_mutex_t   *mutex,
26  Objects_Locations *location
27)
28{
29  if ( mutex == NULL ) {
30    *location = OBJECTS_ERROR;
31
32    return false;
33  }
34
35  if ( *mutex == PTHREAD_MUTEX_INITIALIZER ) {
36    int eno;
37
38    _Once_Lock();
39
40    if ( *mutex == PTHREAD_MUTEX_INITIALIZER ) {
41      eno = pthread_mutex_init( mutex, NULL );
42    } else {
43      eno = 0;
44    }
45
46    _Once_Unlock();
47
48    if ( eno != 0 ) {
49      *location = OBJECTS_ERROR;
50
51      return false;
52    }
53  }
54
55  return true;
56}
57
58POSIX_Mutex_Control *_POSIX_Mutex_Get (
59  pthread_mutex_t   *mutex,
60  Objects_Locations *location
61)
62{
63  if ( !_POSIX_Mutex_Check_id_and_auto_init( mutex, location ) ) {
64    return NULL;
65  }
66
67  return (POSIX_Mutex_Control *)
68    _Objects_Get( &_POSIX_Mutex_Information, (Objects_Id) *mutex, location );
69}
70
71POSIX_Mutex_Control *_POSIX_Mutex_Get_interrupt_disable(
72  pthread_mutex_t  *mutex,
73  ISR_lock_Context *lock_context
74)
75{
76  Objects_Locations location;
77
78  if ( !_POSIX_Mutex_Check_id_and_auto_init( mutex, &location ) ) {
79    return NULL;
80  }
81
82  return (POSIX_Mutex_Control *) _Objects_Get_isr_disable(
83    &_POSIX_Mutex_Information,
84    (Objects_Id) *mutex,
85    &location,
86    lock_context
87  );
88}
Note: See TracBrowser for help on using the repository browser.