From 692b9abe5ff356529b77a09bd1c6170fae1d849f Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Mon, 6 Feb 2017 10:27:01 -0800 Subject: [PATCH] SCP: Add ability to descriptively name UNITs This allows a device simulator to specifically name the units that it uses for different purposes. This info is visible in the output of SHOW QUEUE and debug output. Once specified or dynamically determined (as previously occurred with each call to sim_uname()), that name is saved for fast delivery on subsequent calls. This will remove some overhead when running with debugging on. --- scp.c | 21 ++++++++++++++++----- scp.h | 1 + sim_defs.h | 1 + 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/scp.c b/scp.c index 53da17f2..055629e1 100644 --- a/scp.c +++ b/scp.c @@ -5791,17 +5791,28 @@ return (dptr ? (dptr->lname? dptr->lname: dptr->name) : ""); const char *sim_uname (UNIT *uptr) { -DEVICE *d = find_dev_from_unit(uptr); -static AIO_TLS char uname[CBUFSIZE]; +DEVICE *d; +char uname[CBUFSIZE]; +if (uptr->uname) + return uptr->uname; +d = find_dev_from_unit(uptr); if (!d) return ""; if (d->numunits == 1) - return sim_dname (d); -sprintf (uname, "%s%d", sim_dname (d), (int)(uptr-d->units)); -return uname; + sprintf (uname, "%s", sim_dname (d)); +else + sprintf (uname, "%s%d", sim_dname (d), (int)(uptr-d->units)); +return sim_set_uname (uptr, uname); } +const char *sim_set_uname (UNIT *uptr, const char *uname) +{ +free (uptr->uname); +uptr->uname = strcpy ((char *)malloc (1 + strlen (uname)), uname); +} + + /* Save command sa[ve] filename save state to specified file diff --git a/scp.h b/scp.h index 29ed7d2a..858db320 100644 --- a/scp.h +++ b/scp.h @@ -144,6 +144,7 @@ t_stat reset_all (uint32 start_device); t_stat reset_all_p (uint32 start_device); const char *sim_dname (DEVICE *dptr); const char *sim_uname (UNIT *dptr); +const char *sim_set_uname (UNIT *uptr, const char *uname); t_stat get_yn (const char *ques, t_stat deflt); int sim_isspace (char c); int sim_islower (char c); diff --git a/sim_defs.h b/sim_defs.h index 2ad7a71f..ac3c85f0 100644 --- a/sim_defs.h +++ b/sim_defs.h @@ -547,6 +547,7 @@ struct UNIT { void *tmxr; /* TMXR linkage */ t_bool (*cancel)(UNIT *); double usecs_remaining; /* time balance for long delays */ + char *uname; /* Unit name */ #ifdef SIM_ASYNCH_IO void (*a_check_completion)(UNIT *); t_bool (*a_is_active)(UNIT *);