Subject: |
Re: Permissible in C to call CA I/O functions from callback? |
From: |
Andrew Johnson <[email protected]> |
To: |
<[email protected]> |
Date: |
Thu, 6 Nov 2014 17:11:06 -0600 |
Hi Lewis,
On 11/06/2014 04:51 PM, J. Lewis Muir wrote:
>
> 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?
It is permissible to call most non-blocking CA functions such as
ca_get(), ca_get_callback, ca_put(), ca_put_callback() etc., but not
ca_poll(), ca_pend_io() or ca_pend_event().
If you look through the CA Reference manual, those routines that can
return the code ECA_EVDISALLOW are not permitted within a callback.
> 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?
The ca_get() is fine, but the ca_pend_io() is not allowed and will
return ECA_EVDISALLOW. However if you use ca_get_callback() instead of
ca_get() then you get notification that the data is available through
that callback instead.
The ca_pend_io() routine is never used in this event-driven style of
programming, where all notifications should be triggered by callback
events (even channel connections, so your program can respond
appropriately to disconnection events). The main thread can then become
a single call to ca_pend_event(0) i.e. wait forever, although in
practice it's usually more like
while (!stop)
ca_pend_event(0.1);
exit(0);
to allow the application to set the stop variable and trigger a program
exit.
HTH,
- Andrew
--
People everywhere confuse what they read in newspapers with news.
-- A. J. Liebling
- Replies:
- Re: Permissible in C to call CA I/O functions from callback? J. Lewis Muir
- Re: Permissible in C to call CA I/O functions from callback? J. Lewis Muir
- References:
- Permissible in C to call CA I/O functions from callback? J. Lewis Muir
- Navigate by Date:
- Prev:
Permissible in C to call CA I/O functions from callback? J. Lewis Muir
- Next:
Re: Permissible in C to call CA I/O functions from callback? J. Lewis Muir
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
<2014>
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
- Navigate by Thread:
- Prev:
Permissible in C to call CA I/O functions from callback? J. Lewis Muir
- Next:
Re: Permissible in C to call CA I/O functions from callback? J. Lewis Muir
- Index:
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
<2014>
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
|