[6c2675d] | 1 | /** |
---|
| 2 | * @file rtems/posix/mutex.inl |
---|
| 3 | */ |
---|
| 4 | |
---|
[2b2bda4] | 5 | /* rtems/posix/mutex.inl |
---|
| 6 | * |
---|
| 7 | * This include file contains the macro implementation of the private |
---|
| 8 | * inlined routines for POSIX mutex's. |
---|
| 9 | * |
---|
| 10 | * COPYRIGHT (c) 1989-1999. |
---|
| 11 | * On-Line Applications Research Corporation (OAR). |
---|
| 12 | * |
---|
| 13 | * The license and distribution terms for this file may be |
---|
| 14 | * found in the file LICENSE in this distribution or at |
---|
[8e36f29] | 15 | * http://www.rtems.com/license/LICENSE. |
---|
[2b2bda4] | 16 | * |
---|
| 17 | * $Id$ |
---|
| 18 | */ |
---|
| 19 | |
---|
| 20 | #ifndef __RTEMS_POSIX_MUTEX_inl |
---|
| 21 | #define __RTEMS_POSIX_MUTEX_inl |
---|
| 22 | |
---|
| 23 | /*PAGE |
---|
| 24 | * |
---|
| 25 | * _POSIX_Mutex_Allocate |
---|
| 26 | */ |
---|
| 27 | |
---|
| 28 | #define _POSIX_Mutex_Allocate() \ |
---|
| 29 | (POSIX_Mutex_Control *) _Objects_Allocate( &_POSIX_Mutex_Information ) |
---|
| 30 | |
---|
| 31 | /*PAGE |
---|
| 32 | * |
---|
| 33 | * _POSIX_Mutex_Free |
---|
| 34 | */ |
---|
| 35 | |
---|
| 36 | #define _POSIX_Mutex_Free( _the_mutex ) \ |
---|
| 37 | _Objects_Free( &_POSIX_Mutex_Information, &(_the_mutex)->Object ) |
---|
| 38 | |
---|
| 39 | /*PAGE |
---|
| 40 | * |
---|
| 41 | * _POSIX_Mutex_Get |
---|
| 42 | * |
---|
| 43 | * NOTE: The support macro makes it possible for both to use exactly |
---|
| 44 | * the same code to check for NULL id pointer and |
---|
| 45 | * PTHREAD_MUTEX_INITIALIZER without adding overhead. |
---|
| 46 | */ |
---|
| 47 | |
---|
| 48 | #define ___POSIX_Mutex_Get_support( _id, _location ) \ |
---|
| 49 | do { \ |
---|
| 50 | int _status; \ |
---|
| 51 | \ |
---|
| 52 | if ( !_id ) { \ |
---|
| 53 | *_location = OBJECTS_ERROR; \ |
---|
| 54 | return (POSIX_Mutex_Control *) 0; \ |
---|
| 55 | } \ |
---|
| 56 | \ |
---|
| 57 | if ( *_id == PTHREAD_MUTEX_INITIALIZER ) { \ |
---|
| 58 | /* \ |
---|
| 59 | * Do an "auto-create" here. \ |
---|
| 60 | */ \ |
---|
| 61 | \ |
---|
| 62 | _status = pthread_mutex_init( _id, 0 ); \ |
---|
| 63 | if ( _status ) { \ |
---|
| 64 | *_location = OBJECTS_ERROR; \ |
---|
| 65 | return (POSIX_Mutex_Control *) 0; \ |
---|
| 66 | } \ |
---|
| 67 | } \ |
---|
| 68 | } while (0) |
---|
| 69 | |
---|
[ce92867b] | 70 | /* If we find a compiler that doesn't accept static inline functions, |
---|
| 71 | * then this will have to move to a .c file. Until then, we will use this. |
---|
| 72 | */ |
---|
| 73 | static inline POSIX_Mutex_Control * _POSIX_Mutex_Get( |
---|
[2b2bda4] | 74 | Objects_Id *id, |
---|
| 75 | Objects_Locations *location |
---|
| 76 | ) |
---|
| 77 | { |
---|
| 78 | ___POSIX_Mutex_Get_support( id, location ); |
---|
| 79 | |
---|
| 80 | return (POSIX_Mutex_Control *) |
---|
| 81 | _Objects_Get( &_POSIX_Mutex_Information, *id, location ); |
---|
| 82 | } |
---|
| 83 | |
---|
[ce92867b] | 84 | /* If we find a compiler that doesn't accept static inline functions, |
---|
| 85 | * then this will have to move to a .c file. Until then, we will use this. |
---|
| 86 | */ |
---|
| 87 | static inline POSIX_Mutex_Control *_POSIX_Mutex_Get_interrupt_disable( |
---|
[2b2bda4] | 88 | Objects_Id *id, |
---|
| 89 | Objects_Locations *location, |
---|
| 90 | ISR_Level *level |
---|
| 91 | ) |
---|
| 92 | { |
---|
| 93 | ___POSIX_Mutex_Get_support( id, location ); |
---|
| 94 | |
---|
| 95 | return (POSIX_Mutex_Control *) |
---|
| 96 | _Objects_Get_isr_disable( &_POSIX_Mutex_Information, *id, location, level ); |
---|
| 97 | } |
---|
| 98 | |
---|
| 99 | |
---|
| 100 | /*PAGE |
---|
| 101 | * |
---|
| 102 | * _POSIX_Mutex_Is_null |
---|
| 103 | */ |
---|
| 104 | |
---|
| 105 | #define _POSIX_Mutex_Is_null( _the_mutex ) \ |
---|
| 106 | (!(_the_mutex)) |
---|
| 107 | |
---|
| 108 | #endif |
---|
| 109 | /* end of include file */ |
---|
| 110 | |
---|