1 | /** |
---|
2 | * @file rtems/posix/mutex.inl |
---|
3 | */ |
---|
4 | |
---|
5 | /* rtems/posix/mutex.inl |
---|
6 | * |
---|
7 | * This include file contains the static inline 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 |
---|
15 | * http://www.rtems.com/license/LICENSE. |
---|
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 | RTEMS_INLINE_ROUTINE POSIX_Mutex_Control *_POSIX_Mutex_Allocate( void ) |
---|
29 | { |
---|
30 | return (POSIX_Mutex_Control *) _Objects_Allocate( &_POSIX_Mutex_Information ); |
---|
31 | } |
---|
32 | |
---|
33 | /*PAGE |
---|
34 | * |
---|
35 | * _POSIX_Mutex_Free |
---|
36 | */ |
---|
37 | |
---|
38 | RTEMS_INLINE_ROUTINE void _POSIX_Mutex_Free ( |
---|
39 | POSIX_Mutex_Control *the_mutex |
---|
40 | ) |
---|
41 | { |
---|
42 | _Objects_Free( &_POSIX_Mutex_Information, &the_mutex->Object ); |
---|
43 | } |
---|
44 | |
---|
45 | /*PAGE |
---|
46 | * |
---|
47 | * _POSIX_Mutex_Get_support |
---|
48 | * |
---|
49 | * NOTE: The support macro makes it possible for both to use exactly |
---|
50 | * the same code to check for NULL id pointer and |
---|
51 | * PTHREAD_MUTEX_INITIALIZER without adding overhead. |
---|
52 | */ |
---|
53 | |
---|
54 | #define ___POSIX_Mutex_Get_support( _id, _location ) \ |
---|
55 | do { \ |
---|
56 | int _status; \ |
---|
57 | \ |
---|
58 | if ( !_id ) { \ |
---|
59 | *_location = OBJECTS_ERROR; \ |
---|
60 | return (POSIX_Mutex_Control *) 0; \ |
---|
61 | } \ |
---|
62 | \ |
---|
63 | if ( *_id == PTHREAD_MUTEX_INITIALIZER ) { \ |
---|
64 | /* \ |
---|
65 | * Do an "auto-create" here. \ |
---|
66 | */ \ |
---|
67 | \ |
---|
68 | _status = pthread_mutex_init( _id, 0 ); \ |
---|
69 | if ( _status ) { \ |
---|
70 | *_location = OBJECTS_ERROR; \ |
---|
71 | return (POSIX_Mutex_Control *) 0; \ |
---|
72 | } \ |
---|
73 | } \ |
---|
74 | } while (0) |
---|
75 | |
---|
76 | RTEMS_INLINE_ROUTINE POSIX_Mutex_Control *_POSIX_Mutex_Get ( |
---|
77 | Objects_Id *id, |
---|
78 | Objects_Locations *location |
---|
79 | ) |
---|
80 | { |
---|
81 | ___POSIX_Mutex_Get_support( id, location ); |
---|
82 | |
---|
83 | return (POSIX_Mutex_Control *) |
---|
84 | _Objects_Get( &_POSIX_Mutex_Information, *id, location ); |
---|
85 | } |
---|
86 | |
---|
87 | RTEMS_INLINE_ROUTINE POSIX_Mutex_Control *_POSIX_Mutex_Get_interrupt_disable ( |
---|
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 | RTEMS_INLINE_ROUTINE boolean _POSIX_Mutex_Is_null ( |
---|
106 | POSIX_Mutex_Control *the_mutex |
---|
107 | ) |
---|
108 | { |
---|
109 | return !the_mutex; |
---|
110 | } |
---|
111 | |
---|
112 | #endif |
---|
113 | /* end of include file */ |
---|
114 | |
---|