EPICS Controls 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  2012  2013  <20142015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  <20142015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Permissible in C to call CA I/O functions from callback?
From: "J. Lewis Muir" <[email protected]>
To: EPICS Tech-Talk <[email protected]>
Date: Thu, 06 Nov 2014 16:51:57 -0600
Dear Tech-Talkers,

Is it permissible, in a C program using the EPICS CA client library
using a preemptive CA context, to call CA functions that perform I/O
from a user-supplied callback function?

Here's an example.  A CA client creates a CA context like this:

  status = ca_context_create(ca_enable_preemptive_callback);

It creates a channel and then registers a state change subscription on
it like this:

  status = ca_create_subscription(DBR_LONG, 1, ctx->ch_image_id,
      DBE_VALUE, on_image_id_state_change, ctx, NULL);

And in the on_image_id_state_change callback function, it reads a PV
value like this:

  status = ca_get(DBR_LONG, ctx->ch_nx, &nx);
  if (status != ECA_NORMAL) goto err;
  status = ca_pend_io(ctx->timeout);
  if (status != ECA_NORMAL) goto err;

Is this permissible?

One advantage of doing things this way is that the client doesn't need
a separate thread for handling state change events.  It essentially
just uses "for free" a thread managed by the CA client library.  One
disadvantage is that, since the CA client library guarantees that it
will always wait for a user-supplied callback function to complete
before calling another one, the client won't learn of any state changes
that occur while performing work in the callback function until the
callback function completes.

The client could obviously have it's own "worker" thread that would
handle CA state change events.  The user-supplied callback function
would just notify the worker thread whenever it received a state change
event.  But as I said, this would mean managing a worker thread, which
isn't a big deal, but does increase the complexity.

Thank you!

Lewis

Replies:
Re: Permissible in C to call CA I/O functions from callback? Andrew Johnson

Navigate by Date:
Prev: Re: Delta Tau Turbo PMAC2 VME Ultralight A24/A32 VME address space problem Ron Sluiter
Next: Re: Permissible in C to call CA I/O functions from callback? Andrew Johnson
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  <20142015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Re: Delta Tau Turbo PMAC2 VME Ultralight A24/A32 VME address space problem Ron Sluiter
Next: Re: Permissible in C to call CA I/O functions from callback? Andrew Johnson
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  2011  2012  2013  <20142015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 17 Dec 2015 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·