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
RevLine 
[f9d533a5]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
[4600bd7c]10/*  COPYRIGHT (c) 1989-2013.
[f9d533a5]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
[c499856]15 *  http://www.rtems.org/license/LICENSE.
[f9d533a5]16 */
17
[b8bdced1]18#ifndef _RTEMS_POSIX_MUTEXIMPL_H
19#define _RTEMS_POSIX_MUTEXIMPL_H
20
[f9d533a5]21#include <rtems/posix/mutex.h>
[20e239c2]22#include <rtems/score/coremuteximpl.h>
[f9d533a5]23
[9728ef3]24#include <errno.h>
[b8bdced1]25#include <pthread.h>
[f9d533a5]26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
[4600bd7c]31/**
[f9d533a5]32 *  The following defines the information control block used to manage
33 *  this class of objects.
34 */
[9871f5dc]35extern Objects_Information _POSIX_Mutex_Information;
[f9d533a5]36
[4600bd7c]37/**
[f9d533a5]38 *  The default mutex attributes structure.
39 */
[9871f5dc]40extern pthread_mutexattr_t _POSIX_Mutex_Default_attributes;
[f9d533a5]41
[4600bd7c]42/**
43 *  This array contains a mapping from Score Mutex return codes to
44 *  POSIX return codes.
45 */
[9728ef3]46extern const int _POSIX_Mutex_Return_codes[CORE_MUTEX_STATUS_LAST + 1];
47
[4600bd7c]48/**
49 *  @brief POSIX Mutex Allocate
[f9d533a5]50 *
51 *  This function allocates a mutexes control block from
52 *  the inactive chain of free mutexes control blocks.
53 */
[4600bd7c]54RTEMS_INLINE_ROUTINE POSIX_Mutex_Control *_POSIX_Mutex_Allocate( void )
55{
56  return (POSIX_Mutex_Control *) _Objects_Allocate( &_POSIX_Mutex_Information );
57}
[f9d533a5]58
[4600bd7c]59/**
60 *  @brief POSIX Mutex Free
[f9d533a5]61 *
62 *  This routine frees a mutexes control block to the
63 *  inactive chain of free mutexes control blocks.
64 */
[4600bd7c]65RTEMS_INLINE_ROUTINE void _POSIX_Mutex_Free(
[f9d533a5]66  POSIX_Mutex_Control *the_mutex
[4600bd7c]67)
68{
69  _Objects_Free( &_POSIX_Mutex_Information, &the_mutex->Object );
70}
[f9d533a5]71
72
[4600bd7c]73/**
74 *  @brief POSIX Mutex Lock Support Method
[f9d533a5]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/**
[4600bd7c]86 * @brief Convert Score mutex status codes into POSIX status values
[f9d533a5]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
[4600bd7c]95 *         complete immediately because the resource was unavailable.
[f9d533a5]96 * @retval EDEADLK Mutex status code indicates that an attempt was made to
[4600bd7c]97 *         relock a mutex for which nesting is not configured.
[f9d533a5]98 * @retval EPERM Mutex status code indicates that an attempt was made to
[4600bd7c]99 *         release a mutex by a thread other than the thread which locked it.
[f9d533a5]100 * @retval EINVAL Mutex status code indicates that the thread was blocked
[4600bd7c]101 *         waiting for an operation to complete and the mutex was deleted.
[f9d533a5]102 * @retval ETIMEDOUT Mutex status code indicates that the calling task was
[4600bd7c]103 *         willing to block but the operation was unable to complete
104 *         within the time allotted because the resource never became
105 *         available.
[f9d533a5]106 */
[9728ef3]107RTEMS_INLINE_ROUTINE int _POSIX_Mutex_Translate_core_mutex_return_code(
[f9d533a5]108  CORE_mutex_Status  the_mutex_status
[9728ef3]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}
[f9d533a5]120
[4600bd7c]121/**
122 *  @brief POSIX Mutex Get (Interrupt Disable)
[f9d533a5]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 *
[4600bd7c]127 *  @note: This version of the method uses an interrupt critical section.
[f9d533a5]128 */
[b8bdced1]129POSIX_Mutex_Control *_POSIX_Mutex_Get_interrupt_disable(
130  pthread_mutex_t  *mutex,
131  ISR_lock_Context *lock_context
[f9d533a5]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.