source: rtems-schedsim/schedsim/shell/shared/main_semdelete.c @ 187d93c

Last change on this file since 187d93c was 187d93c, checked in by Joel Sherrill <joel.sherrill@…>, on Apr 30, 2014 at 6:24:50 PM

Allow Scheduler Simulator to "defer dispatch" until controlled

This is needed to prevent a semaphore delete from triggering a
preempt and breaking the mutex is owner debug check. Technically
we are running the same thread until the API call returns. But from
an RTEMS internals perspective, it was preempted at the _Object_Put().

When understanding this patch, it is important to remember that the
Scheduler Simulator is single threaded and faking out RTEMS. This
is one place where RTEMS would have preempted to a thread and when
we returned to rtems_semaphore_delete(), the _Object_Put() call
would have been made by the correct thread.

  • Property mode set to 100644
File size: 1.6 KB
Line 
1/**
2 *  @file
3 *  @brief Task Delete Shell Command Implmentation
4 */
5
6/*
7 *  COPYRIGHT (c) 1989-2014.
8 *  On-Line Applications Research Corporation (OAR).
9 *
10 *  The license and distribution terms for this file may be
11 *  found in the file LICENSE in this distribution or at
12 *  http://www.rtems.com/license/LICENSE.
13 */
14
15#ifdef HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#include <stdio.h>
20
21#include <rtems.h>
22#include "shell.h"
23#include <rtems/stringto.h>
24#include <schedsim_shell.h>
25#include <rtems/error.h>
26
27int rtems_shell_main_semaphore_delete(
28  int   argc,
29  char *argv[]
30)
31{
32  rtems_id           id;
33  rtems_status_code  status;
34 
35  CHECK_RTEMS_IS_UP();
36
37  if (argc != 2) {
38    fprintf( stderr, "%s: Usage [name|id]\n", argv[0] );
39    return -1;
40  }
41
42  if ( lookup_semaphore( argv[1], &id ) )
43    return -1;
44
45  /*
46   *  Now delete the semaphore
47   */
48  printf("Deleting semaphore (0x%08x)\n", id );
49 
50  /*
51   * This wraps the allocator mutex and should defer any context switching
52   */
53  schedsim_set_allow_dispatch(false);
54    status = rtems_semaphore_delete( id );
55  schedsim_set_allow_dispatch(true);
56
57  if ( status != RTEMS_SUCCESSFUL ) {
58    fprintf(
59      stderr,
60      "Semaphore Delete(%s) returned %s\n",
61      argv[1],
62      rtems_status_text( status )
63    ); 
64    return -1;
65  }
66
67  return 0;
68}
69
70rtems_shell_cmd_t rtems_shell_SEMAPHORE_DELETE_Command = {
71  "semaphore_delete",                 /* name */
72  "semaphore_delete name priority",   /* usage */
73  "rtems",                            /* topic */
74  rtems_shell_main_semaphore_delete,  /* command */
75  NULL,                               /* alias */
76  NULL                                /* next */
77};
Note: See TracBrowser for help on using the repository browser.