source: rtems-schedsim/schedsim/shell/shared/lookup_task.c @ a6a8e11

Last change on this file since a6a8e11 was a6a8e11, checked in by Joel Sherrill <joel.sherrill@…>, on May 23, 2014 at 3:57:07 PM

lookup_task.c: Lock around getting executing id.

  • Property mode set to 100644
File size: 1.5 KB
Line 
1/*
2 *  Given Name or ID String, give Id
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 <rtems/stringto.h>
20
21#ifndef METHOD_NAME
22  #define METHOD_NAME lookup_task
23#endif
24#ifndef RTEMS_IDENT_NAME
25  #define RTEMS_IDENT_NAME rtems_task_ident
26  #define DOING_TASKS
27#endif
28
29int METHOD_NAME(
30  const char *string,
31  rtems_id   *id
32)
33{
34  char               name[5];
35  rtems_status_code  status;
36  unsigned long      tmp;
37
38  if ( string[0] != '0' ) {
39    #ifdef DOING_TASKS
40      if ( !strcmp( string, "SELF" ) ) {
41        _Thread_Disable_dispatch();
42          *id = _Thread_Executing->Object.id;
43        _Thread_Enable_dispatch();
44        return 0;
45      }
46    #endif
47    if ( strlen( string ) != 4 ) {
48      return -1;
49    }
50    memset( name, '\0', sizeof(name) );
51    strncpy( name, string, 4 );
52    status = RTEMS_IDENT_NAME(
53      rtems_build_name( name[0], name[1], name[2], name[3] ),
54      OBJECTS_SEARCH_ALL_NODES,
55      id
56    );
57    if ( status != RTEMS_SUCCESSFUL )
58      return 1;
59  } else {
60    if ( rtems_string_to_unsigned_long( string, &tmp, NULL, 0) ) {
61      fprintf( stderr, "Argument (%s) is not a number\n", string );
62      return 1;
63    }
64    *id = (rtems_id) tmp;
65  }
66
67  return 0;
68}
Note: See TracBrowser for help on using the repository browser.