source: rtems/cpukit/posix/include/rtems/posix/muteximpl.h @ 48b04fc3

5
Last change on this file since 48b04fc3 was 48b04fc3, checked in by Sebastian Huber <sebastian.huber@…>, on 04/19/16 at 04:28:03

posix: Avoid Giant lock for mutexes

Delete _POSIX_Mutex_Get(). Use _POSIX_Mutex_Get_interrupt_disable()
instead.

Update #2555.

  • Property mode set to 100644
File size: 3.9 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#ifndef _RTEMS_POSIX_MUTEXIMPL_H
19#define _RTEMS_POSIX_MUTEXIMPL_H
20
21#include <rtems/posix/mutex.h>
22#include <rtems/score/coremuteximpl.h>
23
24#include <errno.h>
25#include <pthread.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31/**
32 *  The following defines the information control block used to manage
33 *  this class of objects.
34 */
35extern Objects_Information _POSIX_Mutex_Information;
36
37/**
38 *  The default mutex attributes structure.
39 */
40extern pthread_mutexattr_t _POSIX_Mutex_Default_attributes;
41
42/**
43 *  This array contains a mapping from Score Mutex return codes to
44 *  POSIX return codes.
45 */
46extern const int _POSIX_Mutex_Return_codes[CORE_MUTEX_STATUS_LAST + 1];
47
48/**
49 *  @brief POSIX Mutex Allocate
50 *
51 *  This function allocates a mutexes control block from
52 *  the inactive chain of free mutexes control blocks.
53 */
54RTEMS_INLINE_ROUTINE POSIX_Mutex_Control *_POSIX_Mutex_Allocate( void )
55{
56  return (POSIX_Mutex_Control *) _Objects_Allocate( &_POSIX_Mutex_Information );
57}
58
59/**
60 *  @brief POSIX Mutex Free
61 *
62 *  This routine frees a mutexes control block to the
63 *  inactive chain of free mutexes control blocks.
64 */
65RTEMS_INLINE_ROUTINE void _POSIX_Mutex_Free(
66  POSIX_Mutex_Control *the_mutex
67)
68{
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 (Interrupt 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 an interrupt critical section.
128 */
129POSIX_Mutex_Control *_POSIX_Mutex_Get_interrupt_disable(
130  pthread_mutex_t  *mutex,
131  ISR_lock_Context *lock_context
132);
133
134#ifdef __cplusplus
135}
136#endif
137
138#endif
139/*  end of include file */
140
Note: See TracBrowser for help on using the repository browser.