forked from Imagelibrary/rtems
The holder field is enough to determine if a mutex is locked or not. This leads also to better error status codes in case a rtems_semaphore_release() is done for a mutex without having the ownership.
90 lines
2.4 KiB
C
90 lines
2.4 KiB
C
/*
|
|
* RTEMS Monitor semaphore support
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
#include "config.h"
|
|
#endif
|
|
|
|
#include <rtems.h>
|
|
#include "monitor.h"
|
|
#include <rtems/rtems/attrimpl.h>
|
|
#include <stdio.h>
|
|
#include <string.h> /* memcpy() */
|
|
|
|
void
|
|
rtems_monitor_sema_canonical(
|
|
rtems_monitor_sema_t *canonical_sema,
|
|
const void *sema_void
|
|
)
|
|
{
|
|
const Semaphore_Control *rtems_sema = (const Semaphore_Control *) sema_void;
|
|
|
|
canonical_sema->attribute = rtems_sema->attribute_set;
|
|
canonical_sema->priority_ceiling =
|
|
rtems_sema->Core_control.mutex.Attributes.priority_ceiling;
|
|
|
|
canonical_sema->holder_id = 0;
|
|
|
|
if (_Attributes_Is_counting_semaphore(canonical_sema->attribute)) {
|
|
/* we have a counting semaphore */
|
|
canonical_sema->cur_count =
|
|
rtems_sema->Core_control.semaphore.count;
|
|
|
|
canonical_sema->max_count =
|
|
rtems_sema->Core_control.semaphore.Attributes.maximum_count;
|
|
}
|
|
else {
|
|
/* we have a binary semaphore (mutex) */
|
|
Thread_Control *holder = rtems_sema->Core_control.mutex.holder;
|
|
|
|
if (holder != NULL) {
|
|
canonical_sema->holder_id = holder->Object.id;
|
|
canonical_sema->cur_count = 0;
|
|
} else {
|
|
canonical_sema->cur_count = 1;
|
|
}
|
|
|
|
canonical_sema->max_count = 1; /* mutex is either 0 or 1 */
|
|
}
|
|
}
|
|
|
|
|
|
void
|
|
rtems_monitor_sema_dump_header(
|
|
bool verbose __attribute__((unused))
|
|
)
|
|
{
|
|
printf("\
|
|
ID NAME ATTR PRICEIL CURR_CNT HOLDID \n");
|
|
/*23456789 123456789 123456789 123456789 123456789 123456789 123456789 1234
|
|
1 2 3 4 5 6 7 */
|
|
|
|
rtems_monitor_separator();
|
|
}
|
|
|
|
/*
|
|
*/
|
|
|
|
void
|
|
rtems_monitor_sema_dump(
|
|
rtems_monitor_sema_t *monitor_sema,
|
|
bool verbose __attribute__((unused))
|
|
)
|
|
{
|
|
int length = 0;
|
|
|
|
length += rtems_monitor_dump_id(monitor_sema->id);
|
|
length += rtems_monitor_pad(11, length);
|
|
length += rtems_monitor_dump_name(monitor_sema->id);
|
|
length += rtems_monitor_pad(18, length);
|
|
length += rtems_monitor_dump_attributes(monitor_sema->attribute);
|
|
length += rtems_monitor_pad(30, length);
|
|
length += rtems_monitor_dump_priority(monitor_sema->priority_ceiling);
|
|
length += rtems_monitor_pad(38, length);
|
|
length += rtems_monitor_dump_decimal(monitor_sema->cur_count);
|
|
length += rtems_monitor_pad(47, length);
|
|
length += rtems_monitor_dump_id(monitor_sema->holder_id);
|
|
printf("\n");
|
|
}
|