source: rtems/cpukit/posix/include/rtems/posix/muteximpl.h @ beba41b

5
Last change on this file since beba41b was 9871f5dc, checked in by Sebastian Huber <sebastian.huber@…>, on 12/14/15 at 15:31:44

Optional POSIX Mutex initialization

Update #2408.

  • Property mode set to 100644
File size: 4.3 KB
Line 
1/**
2 * @file
3 *
4 * @brief Private Inlined Routines for POSIX Mutex's.
5 *
6 * This include file contains the static inline implementation of the private
7 * inlined routines for POSIX mutex's.
8 */
9
10/*  COPYRIGHT (c) 1989-2013.
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.org/license/LICENSE.
16 */
17
18#include <rtems/posix/mutex.h>
19#include <rtems/score/coremuteximpl.h>
20
21#include <errno.h>
22
23#ifndef _RTEMS_POSIX_MUTEXIMPL_H
24#define _RTEMS_POSIX_MUTEXIMPL_H
25
26#ifdef __cplusplus
27extern "C" {
28#endif
29
30/**
31 *  The following defines the information control block used to manage
32 *  this class of objects.
33 */
34extern Objects_Information _POSIX_Mutex_Information;
35
36/**
37 *  The default mutex attributes structure.
38 */
39extern pthread_mutexattr_t _POSIX_Mutex_Default_attributes;
40
41/**
42 *  This array contains a mapping from Score Mutex return codes to
43 *  POSIX return codes.
44 */
45extern const int _POSIX_Mutex_Return_codes[CORE_MUTEX_STATUS_LAST + 1];
46
47/**
48 *  @brief POSIX Mutex Allocate
49 *
50 *  This function allocates a mutexes control block from
51 *  the inactive chain of free mutexes control blocks.
52 */
53RTEMS_INLINE_ROUTINE POSIX_Mutex_Control *_POSIX_Mutex_Allocate( void )
54{
55  return (POSIX_Mutex_Control *) _Objects_Allocate( &_POSIX_Mutex_Information );
56}
57
58/**
59 *  @brief POSIX Mutex Free
60 *
61 *  This routine frees a mutexes control block to the
62 *  inactive chain of free mutexes control blocks.
63 */
64RTEMS_INLINE_ROUTINE void _POSIX_Mutex_Free(
65  POSIX_Mutex_Control *the_mutex
66)
67{
68  _CORE_mutex_Destroy( &the_mutex->Mutex );
69  _Objects_Free( &_POSIX_Mutex_Information, &the_mutex->Object );
70}
71
72
73/**
74 *  @brief POSIX Mutex Lock Support Method
75 *
76 *  A support routine which implements guts of the blocking, non-blocking, and
77 *  timed wait version of mutex lock.
78 */
79int _POSIX_Mutex_Lock_support(
80  pthread_mutex_t           *mutex,
81  bool                       blocking,
82  Watchdog_Interval          timeout
83);
84
85/**
86 * @brief Convert Score mutex status codes into POSIX status values
87 *
88 * A support routine which converts core mutex status codes into the
89 * appropriate POSIX status values.
90 *
91 * @param[in] the_mutex_status is the mutex status code to translate
92 *
93 * @retval 0 Mutex status code indicates the operation completed successfully.
94 * @retval EBUSY Mutex status code indicates that the operation unable to
95 *         complete immediately because the resource was unavailable.
96 * @retval EDEADLK Mutex status code indicates that an attempt was made to
97 *         relock a mutex for which nesting is not configured.
98 * @retval EPERM Mutex status code indicates that an attempt was made to
99 *         release a mutex by a thread other than the thread which locked it.
100 * @retval EINVAL Mutex status code indicates that the thread was blocked
101 *         waiting for an operation to complete and the mutex was deleted.
102 * @retval ETIMEDOUT Mutex status code indicates that the calling task was
103 *         willing to block but the operation was unable to complete
104 *         within the time allotted because the resource never became
105 *         available.
106 */
107RTEMS_INLINE_ROUTINE int _POSIX_Mutex_Translate_core_mutex_return_code(
108  CORE_mutex_Status  the_mutex_status
109)
110{
111  /*
112   *  Internal consistency check for bad status from SuperCore
113   */
114  #if defined(RTEMS_DEBUG)
115    if ( the_mutex_status > CORE_MUTEX_STATUS_LAST )
116      return EINVAL;
117  #endif
118  return _POSIX_Mutex_Return_codes[the_mutex_status];
119}
120
121/**
122 *  @brief POSIX Mutex Get (Thread Dispatch Disable)
123 *
124 *  A support routine which translates the mutex id into a local pointer.
125 *  As a side-effect, it may create the mutex.
126 *
127 *  @note This version of the method uses a dispatching critical section.
128 */
129POSIX_Mutex_Control *_POSIX_Mutex_Get (
130  pthread_mutex_t   *mutex,
131  Objects_Locations *location
132);
133
134/**
135 *  @brief POSIX Mutex Get (Interrupt Disable)
136 *
137 *  A support routine which translates the mutex id into a local pointer.
138 *  As a side-effect, it may create the mutex.
139 *
140 *  @note: This version of the method uses an interrupt critical section.
141 */
142POSIX_Mutex_Control *_POSIX_Mutex_Get_interrupt_disable (
143  pthread_mutex_t   *mutex,
144  Objects_Locations *location,
145  ISR_lock_Context  *lock_context
146);
147
148#ifdef __cplusplus
149}
150#endif
151
152#endif
153/*  end of include file */
154
Note: See TracBrowser for help on using the repository browser.