g+
g+ Communities
Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014 
<== Date ==> <== Thread ==>

Subject: Registering DBD files and iocshRegisterCommon
From: <michael.abbott@diamond.ac.uk>
To: <tech-talk@aps.anl.gov>
Date: Wed, 5 Dec 2012 07:38:30 +0000
I have two questions:

1. Is iocshRegisterCommon() defined to be idempotent (ie, safe to call repeatedly)?

2. Is what I'm trying to do below sane?


I am looking into creating a mechanism for dynamically loading EPICS support modules and it looks as if I need to add an xxx_registerRecordDeviceDriver.cpp file to each support module that I wish to be able to use so that I have a dbd registration function available to call.

Loading a dynamically generated support module requires the following steps:

1. Load the .so file.

2. Load the .dbd file (dbLoadDatabase seems to serve).

3. Register the dbd functionality.

Of course, step 3 is the tricky one.  I've experimented by adding the appropriate <module>_registerRecordDeviceDriver.cpp to the support module's build and then dynamically invoking the generated <module>_registerRecordDeviceDriver function ... and everything seems to work, but I am worried by one small detail.

The generated code, generated by registerRecordDeviceDriver.pl from the module's .dbd file, is straightforward enough, but it always includes a call to iocshRegisterCommon() which gets called at C++ static constructor initialisation time ... which means if I'm generating register functions for every support module *and* for my base IOC this function will be called repeatedly.  I imagine there's no particular guarantee that this function is idempotent, is there?

First of all, is this a sane approach for what I'm trying to achieve?

Secondly, is this safe at the moment?  I've dug into iocshRegisterCommon and its calls, and its work seems to devolve to numerous calls to iocshRegister, which looks properly monotonic to me, so I'm encouraged to proceed.

Could we perhaps make the fact that iocshRegisterCommon can safely be called repeatedly more explicit by applying the following patch?


diff --git a/src/misc/iocshRegisterCommon.c b/src/misc/iocshRegisterCommon.c
index 3e027eb..838de43 100644
--- a/src/misc/iocshRegisterCommon.c
+++ b/src/misc/iocshRegisterCommon.c
@@ -21,8 +21,14 @@
 #include "miscIocRegister.h"
 #include "iocshRegisterCommon.h"
 
+static int initialised = 0;
+
 void epicsShareAPI iocshRegisterCommon(void)
 {
+    if (initialised)
+        return;
+    initialised = 1;
+
     iocshPpdbbase = &pdbbase;
 
     dbStaticIocRegister();



-- 
This e-mail and any attachments may contain confidential, copyright and or privileged material, and are for the use of the intended addressee only. If you are not the intended addressee or an authorised recipient of the addressee please notify us of receipt by returning the e-mail and do not use, copy, retain, distribute or disclose the information in or attached to the e-mail.
Any opinions expressed within this e-mail are those of the individual and not necessarily of Diamond Light Source Ltd. 
Diamond Light Source Ltd. cannot guarantee that this e-mail or any attachments are free from viruses and we cannot accept liability for any damage which you may sustain as a result of software viruses which may be transmitted in or with the message.
Diamond Light Source Limited (company no. 4375679). Registered in England and Wales with its registered office at Diamond House, Harwell Science and Innovation Campus, Didcot, Oxfordshire, OX11 0DE, United Kingdom
 





Replies:
Re: Registering DBD files and iocshRegisterCommon Andrew Johnson

Navigate by Date:
Prev: RE: Initializing starting position on a Motor Mark Rivers
Next: EPICS driver for E-517 Rau, Steffen
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014 
Navigate by Thread:
Prev: RE: Initializing starting position on a Motor Tonia Batten
Next: Re: Registering DBD files and iocshRegisterCommon Andrew Johnson
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  <20122013  2014 
ANJ, 18 Nov 2013 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· EPICSv4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·