source: rtems-schedsim/schedsim/shell/shared/main_semobtain.c @ a2aad55

Last change on this file since a2aad55 was a2aad55, checked in by Joel Sherrill <joel.sherrill@…>, on May 1, 2013 at 12:41:56 AM

Remove CVS $

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/*
2 *  Task Delete Shell Command Implmentation
3 *
4 *  COPYRIGHT (c) 1989-2013.
5 *  On-Line Applications Research Corporation (OAR).
6 *
7 *  The license and distribution terms for this file may be
8 *  found in the file LICENSE in this distribution or at
9 *  http://www.rtems.com/license/LICENSE.
10 */
11
12#ifdef HAVE_CONFIG_H
13#include "config.h"
14#endif
15
16#include <stdio.h>
17
18#include <rtems.h>
19#include "shell.h"
20#include <rtems/stringto.h>
21#include <schedsim_shell.h>
22#include <rtems/error.h>
23
24int rtems_shell_main_semaphore_obtain(
25  int   argc,
26  char *argv[]
27)
28{
29  rtems_id           id;
30  rtems_status_code  status;
31  long               tmp;
32  rtems_interval     ticks;
33  Thread_Control    *caller;
34 
35  /* XXX for now, do not support polling */
36
37  CHECK_RTEMS_IS_UP();
38
39  if (argc != 3) {
40    fprintf( stderr, "%s: Usage name|id timeout\n", argv[0] );
41    return -1;
42  }
43
44  if ( lookup_semaphore( argv[1], &id ) )
45    return -1;
46
47  if ( rtems_string_to_long(argv[2], &tmp, NULL, 0) ) {
48    printf( "Ceiling argument (%s) is not a number\n", argv[1] );
49    return -1;
50  }
51  ticks = tmp;
52
53  /*
54   *  Now obtain the semaphore
55   *
56   *  If the calling thread blocks, we will return as another thread
57   *  but with a "unsatisfied" return code.  So we check that we did
58   *  a thread switch inside the semaphore obtain.  If we did, then
59   *  just return successfully.
60   */
61  caller = _Thread_Executing;
62  printf("Obtain semaphore (0x%08x) with timeout %d\n", id, ticks );
63  status = rtems_semaphore_obtain( id, RTEMS_DEFAULT_OPTIONS, ticks );
64  if ( caller == _Thread_Executing ) {
65    if ( status != RTEMS_SUCCESSFUL ) {
66      fprintf(
67        stderr,
68        "Semaphore obtain(%s) returned %s\n",
69        argv[1],
70        rtems_status_text( status )
71      ); 
72      return -1;
73    }
74  }
75  return 0;
76}
77
78rtems_shell_cmd_t rtems_shell_SEMAPHORE_OBTAIN_Command = {
79  "semaphore_obtain",                /* name */
80  "semaphore_obtain name ticks",     /* usage */
81  "rtems",                           /* topic */
82  rtems_shell_main_semaphore_obtain, /* command */
83  NULL,                              /* alias */
84  NULL                               /* next */
85};
Note: See TracBrowser for help on using the repository browser.