source: rtems/cpukit/posix/src/mutexlocksupp.c @ 33e250c9

5
Last change on this file since 33e250c9 was 33e250c9, checked in by Sebastian Huber <sebastian.huber@…>, on 05/27/16 at 13:41:41

score: Rework CORE priority ceiling mutex

Rework seize and surrender methods to use CORE_ceiling_mutex_Control.
This eliminates CORE_mutex_Disciplines.

  • Property mode set to 100644
File size: 2.2 KB
Line 
1/**
2 * @file
3 *
4 * @brief Support Call to function Enables Locking of Mutex Object
5 * @ingroup POSIXAPI
6 */
7
8/*
9 *  COPYRIGHT (c) 1989-2014.
10 *  On-Line Applications Research Corporation (OAR).
11 *
12 *  The license and distribution terms for this file may be
13 *  found in the file LICENSE in this distribution or at
14 *  http://www.rtems.org/license/LICENSE.
15 */
16
17#if HAVE_CONFIG_H
18#include "config.h"
19#endif
20
21#include <rtems/posix/muteximpl.h>
22#include <rtems/posix/posixapi.h>
23
24THREAD_QUEUE_OBJECT_ASSERT(
25  POSIX_Mutex_Control,
26  Mutex.Recursive.Mutex.Wait_queue
27);
28
29static Status_Control _POSIX_Mutex_Lock_nested(
30  CORE_recursive_mutex_Control *the_recursive_mutex
31)
32{
33  POSIX_Mutex_Control *the_mutex;
34
35  the_mutex = RTEMS_CONTAINER_OF(
36    the_recursive_mutex,
37    POSIX_Mutex_Control,
38    Mutex.Recursive
39  );
40
41  if ( the_mutex->is_recursive ) {
42    return _CORE_recursive_mutex_Seize_nested( the_recursive_mutex );
43  } else {
44    return STATUS_NESTING_NOT_ALLOWED;
45  }
46}
47
48int _POSIX_Mutex_Lock_support(
49  pthread_mutex_t   *mutex,
50  bool               wait,
51  Watchdog_Interval  timeout
52)
53{
54  POSIX_Mutex_Control  *the_mutex;
55  Thread_queue_Context  queue_context;
56  Thread_Control       *executing;
57  Status_Control        status;
58
59  the_mutex = _POSIX_Mutex_Get( mutex, &queue_context );
60
61  if ( the_mutex == NULL ) {
62    return EINVAL;
63  }
64
65  executing = _Thread_Executing;
66
67  switch ( the_mutex->protocol ) {
68    case POSIX_MUTEX_PRIORITY_CEILING:
69      status = _CORE_ceiling_mutex_Seize(
70        &the_mutex->Mutex,
71        executing,
72        wait,
73        timeout,
74        _POSIX_Mutex_Lock_nested,
75        &queue_context
76      );
77      break;
78    case POSIX_MUTEX_NO_PROTOCOL:
79      status = _CORE_recursive_mutex_Seize_no_protocol(
80        &the_mutex->Mutex.Recursive,
81        POSIX_MUTEX_NO_PROTOCOL_TQ_OPERATIONS,
82        executing,
83        wait,
84        timeout,
85        _POSIX_Mutex_Lock_nested,
86        &queue_context
87      );
88      break;
89    default:
90      _Assert( the_mutex->protocol == POSIX_MUTEX_PRIORITY_INHERIT );
91      status = _CORE_mutex_Seize(
92        &the_mutex->Mutex.Recursive.Mutex,
93        executing,
94        wait,
95        timeout,
96        &queue_context
97      );
98      break;
99  }
100
101  return _POSIX_Get_error( status );
102}
Note: See TracBrowser for help on using the repository browser.