source: rtems/cpukit/posix/src/mutexlocksupp.c @ 8797c76

5
Last change on this file since 8797c76 was 8797c76, checked in by Sebastian Huber <sebastian.huber@…>, on 09/27/16 at 13:23:00

score: Unify CORE mutex seize/surrender

Use the Thread_Control::resource_count for the no protocol mutexes.
Merge the no protocol and priority inherit CORE mutex seize/surrender
operations.

  • Property mode set to 100644
File size: 2.3 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  _Thread_queue_Context_set_relative_timeout( &queue_context, timeout );
67
68  switch ( the_mutex->protocol ) {
69    case POSIX_MUTEX_PRIORITY_CEILING:
70      status = _CORE_ceiling_mutex_Seize(
71        &the_mutex->Mutex,
72        executing,
73        wait,
74        _POSIX_Mutex_Lock_nested,
75        &queue_context
76      );
77      break;
78    case POSIX_MUTEX_NO_PROTOCOL:
79      status = _CORE_recursive_mutex_Seize(
80        &the_mutex->Mutex.Recursive,
81        POSIX_MUTEX_NO_PROTOCOL_TQ_OPERATIONS,
82        executing,
83        wait,
84        _POSIX_Mutex_Lock_nested,
85        &queue_context
86      );
87      break;
88    default:
89      _Assert( the_mutex->protocol == POSIX_MUTEX_PRIORITY_INHERIT );
90      status = _CORE_recursive_mutex_Seize(
91        &the_mutex->Mutex.Recursive,
92        CORE_MUTEX_TQ_PRIORITY_INHERIT_OPERATIONS,
93        executing,
94        wait,
95        _POSIX_Mutex_Lock_nested,
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.