source: rtems/cpukit/posix/src/mutexget.c @ 9a845e17

4.104.115
Last change on this file since 9a845e17 was 8860ecf2, checked in by Joel Sherrill <joel.sherrill@…>, on 07/06/09 at 22:02:34

2009-07-06 Joel Sherrill <joel.sherrill@…>

  • posix/src/mutexget.c: Restructure to improve ability to do coverage analysis.
  • Property mode set to 100644
File size: 2.2 KB
Line 
1/*
2 *  Convert POSIX Mutex ID to local object pointer
3 *
4 *  COPYRIGHT (c) 1989-2007.
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 <errno.h>
19#include <pthread.h>
20
21#include <rtems/system.h>
22#include <rtems/score/coremutex.h>
23#if defined(RTEMS_MULTIPROCESSING)
24#include <rtems/score/mpci.h>
25#endif
26#include <rtems/posix/mutex.h>
27
28
29/*
30 *  _POSIX_Mutex_Get_support
31 *
32 *  NOTE: The support macro makes it possible for both to use exactly
33 *        the same code to check for NULL id pointer and
34 *        PTHREAD_MUTEX_INITIALIZER without adding overhead.
35 */
36
37#define ___POSIX_Mutex_Get_support_error_check( _id, _location ) \
38  do { \
39    if ( !_id ) { \
40      *_location = OBJECTS_ERROR; \
41      return (POSIX_Mutex_Control *) 0; \
42    }  \
43  } while (0)
44
45#define ___POSIX_Mutex_Get_support_auto_initialization( _id, _location ) \
46  do { \
47    int _status; \
48    \
49    if ( *_id == PTHREAD_MUTEX_INITIALIZER ) { \
50      /* \
51       *  Do an "auto-create" here. \
52       */ \
53      \
54      _status = pthread_mutex_init( (pthread_mutex_t *)_id, 0 ); \
55      if ( _status ) { \
56        *_location = OBJECTS_ERROR;  \
57        return (POSIX_Mutex_Control *) 0; \
58      } \
59    } \
60  } while (0)
61 
62POSIX_Mutex_Control *_POSIX_Mutex_Get (
63  pthread_mutex_t   *mutex,
64  Objects_Locations *location
65)
66{
67  ___POSIX_Mutex_Get_support_error_check( mutex, location );
68
69  ___POSIX_Mutex_Get_support_auto_initialization( mutex, location );
70
71  return (POSIX_Mutex_Control *)
72    _Objects_Get( &_POSIX_Mutex_Information, (Objects_Id) *mutex, location );
73}
74
75POSIX_Mutex_Control *_POSIX_Mutex_Get_interrupt_disable (
76  pthread_mutex_t   *mutex,
77  Objects_Locations *location,
78  ISR_Level         *level
79)
80{
81  ___POSIX_Mutex_Get_support_error_check( mutex, location );
82
83  ___POSIX_Mutex_Get_support_auto_initialization( mutex, location );
84
85  return (POSIX_Mutex_Control *) _Objects_Get_isr_disable(
86    &_POSIX_Mutex_Information,
87    (Objects_Id) *mutex,
88    location,
89    level
90  );
91}
Note: See TracBrowser for help on using the repository browser.