source: rtems/cpukit/libmisc/monitor/mon-sema.c @ 3692095

Last change on this file since 3692095 was 3692095, checked in by Sebastian Huber <sebastian.huber@…>, on May 30, 2016 at 8:41:22 AM

rtems: Move MrsP semaphore operations

Move MrsP semaphore operations to a less prominent location. Fix field
name.

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/*
2 * RTEMS Monitor semaphore support
3 */
4
5#ifdef HAVE_CONFIG_H
6#include "config.h"
7#endif
8
9#include <rtems.h>
10#include "monitor.h"
11#include <rtems/rtems/semimpl.h>
12#include <stdio.h>
13#include <string.h>    /* memcpy() */
14
15void
16rtems_monitor_sema_canonical(
17    rtems_monitor_sema_t  *canonical_sema,
18    const void            *sema_void
19)
20{
21    const Semaphore_Control *rtems_sema = (const Semaphore_Control *) sema_void;
22    Thread_Control *owner;
23
24    memset(canonical_sema, 0, sizeof(*canonical_sema));
25
26#if defined(RTEMS_MULTIPROCESSING)
27    if (rtems_sema->is_global) {
28      canonical_sema->attribute |= RTEMS_GLOBAL;
29    }
30#endif
31
32    if (rtems_sema->discipline == SEMAPHORE_DISCIPLINE_PRIORITY) {
33      canonical_sema->attribute |= RTEMS_PRIORITY;
34    }
35
36    switch ( rtems_sema->variant ) {
37      case SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY:
38        canonical_sema->attribute |= RTEMS_BINARY_SEMAPHORE
39          | RTEMS_INHERIT_PRIORITY;
40        break;
41      case SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING:
42        canonical_sema->attribute |= RTEMS_BINARY_SEMAPHORE
43          | RTEMS_PRIORITY_CEILING;
44        break;
45      case SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL:
46        canonical_sema->attribute |= RTEMS_BINARY_SEMAPHORE;
47        break;
48#if defined(RTEMS_SMP)
49      case SEMAPHORE_VARIANT_MRSP:
50        canonical_sema->attribute |= RTEMS_BINARY_SEMAPHORE
51          | RTEMS_MULTIPROCESSOR_RESOURCE_SHARING;
52        break;
53#endif
54      case SEMAPHORE_VARIANT_SIMPLE_BINARY:
55        canonical_sema->attribute |= RTEMS_SIMPLE_BINARY_SEMAPHORE;
56        break;
57      case SEMAPHORE_VARIANT_COUNTING:
58        canonical_sema->attribute |= RTEMS_COUNTING_SEMAPHORE;
59        break;
60    }
61
62    switch ( rtems_sema->variant ) {
63      case SEMAPHORE_VARIANT_MUTEX_PRIORITY_CEILING:
64        canonical_sema->priority_ceiling =
65          rtems_sema->Core_control.Mutex.priority_ceiling;
66        /* Fall through */
67      case SEMAPHORE_VARIANT_MUTEX_INHERIT_PRIORITY:
68      case SEMAPHORE_VARIANT_MUTEX_NO_PROTOCOL:
69        owner = _CORE_mutex_Get_owner(
70          &rtems_sema->Core_control.Mutex.Recursive.Mutex
71        );
72
73        if (owner != NULL) {
74          canonical_sema->holder_id = owner->Object.id;
75          canonical_sema->cur_count = 0;
76        } else {
77          canonical_sema->cur_count = 1;
78        }
79
80        canonical_sema->max_count = 1;
81        break;
82#if defined(RTEMS_SMP)
83      case SEMAPHORE_VARIANT_MRSP:
84        canonical_sema->cur_count =
85          rtems_sema->Core_control.MRSP.Resource.owner == NULL;
86        canonical_sema->max_count = 1;
87        break;
88#endif
89      case SEMAPHORE_VARIANT_SIMPLE_BINARY:
90        canonical_sema->cur_count = rtems_sema->Core_control.semaphore.count;
91        canonical_sema->max_count = 1;
92        break;
93      case SEMAPHORE_VARIANT_COUNTING:
94        canonical_sema->cur_count = rtems_sema->Core_control.semaphore.count;
95        canonical_sema->max_count = UINT32_MAX;
96        break;
97    }
98}
99
100
101void
102rtems_monitor_sema_dump_header(
103    bool verbose RTEMS_UNUSED
104)
105{
106    printf("\
107  ID       NAME   ATTR        PRICEIL CURR_CNT HOLDID \n");
108/*23456789 123456789 123456789 123456789 123456789 123456789 123456789 1234
109          1         2         3         4         5         6         7    */
110
111    rtems_monitor_separator();
112}
113
114/*
115 */
116
117void
118rtems_monitor_sema_dump(
119    rtems_monitor_sema_t *monitor_sema,
120    bool  verbose RTEMS_UNUSED
121)
122{
123    int length = 0;
124
125    length += rtems_monitor_dump_id(monitor_sema->id);
126    length += rtems_monitor_pad(11, length);
127    length += rtems_monitor_dump_name(monitor_sema->id);
128    length += rtems_monitor_pad(18, length);
129    length += rtems_monitor_dump_attributes(monitor_sema->attribute);
130    length += rtems_monitor_pad(30, length);
131    length += rtems_monitor_dump_priority(monitor_sema->priority_ceiling);
132    length += rtems_monitor_pad(38, length);
133    length += rtems_monitor_dump_decimal(monitor_sema->cur_count);
134    length += rtems_monitor_pad(47, length);
135    length += rtems_monitor_dump_id(monitor_sema->holder_id);
136    printf("\n");
137}
Note: See TracBrowser for help on using the repository browser.