On Tue, 2010-04-20 at 01:43 +0200, Jan Kiszka wrote:
> Philippe Gerum wrote:
> > On Mon, 2010-04-19 at 12:28 +0200, Jan Kiszka wrote:
> >> This adds rtdm_rt_capable(), a function that can be used by drivers to
> >> detect callers that could issue a service request also from the
> >> (typically preferred) real-time context. If that is the case, the driver
> >> can trigger a restart of the request if the current context is not
> >> real-time.
> >>
> >> CC: Philippe Gerum <r...@xenomai.org>
> >> CC: Alexis Berlemont <berlemont.h...@free.fr>
> >> Signed-off-by: Jan Kiszka <jan.kis...@siemens.com>
> >> ---
> >>  include/rtdm/rtdm_driver.h |    6 ++++++
> >>  ksrc/skins/rtdm/drvlib.c   |   25 +++++++++++++++++++++++++
> >>  2 files changed, 31 insertions(+), 0 deletions(-)
> >>
> >> diff --git a/include/rtdm/rtdm_driver.h b/include/rtdm/rtdm_driver.h
> >> index 0fc1496..d124157 100644
> >> --- a/include/rtdm/rtdm_driver.h
> >> +++ b/include/rtdm/rtdm_driver.h
> >> @@ -1296,6 +1296,12 @@ static inline int rtdm_in_rt_context(void)
> >>  {
> >>    return (rthal_current_domain != rthal_root_domain);
> >>  }
> >> +
> >> +static inline int rtdm_rt_capable(void)
> >> +{
> >> +  return (!xnpod_root_p() || xnshadow_thread(current) != NULL);
> >> +}
> >> +
> > 
> > This patch still has fundamental flaw, the service would not work
> > correctly and would actually return the wrong value, in case it is used
> > deeply buried into some helper code, traversed by asynchronous Xenomai
> > contexts.
> 
> Using it from that contexts would be the fundamental flaw. We can catch
> this, though.
> 

Sure, but this API is supposed to help people to deal with context
issues by providing unambiguous services.

> > At the very least, you should avoid this by binding that
> > service to a valid rtdm_dev_context, so that you know that it is called
> > from a context that is correct in the first place, where a
> > rtdm_dev_context reference is available.
> > 
> > I.e. 
> > static inline int rtdm_rt_capable(struct rtdm_dev_context *context), and
> > extract the information from that context structure. That would avoid a
> > lot of headaches down the road to your user base.
> 
> The context is not that helpful here.
> 
> But instead of using current, we can force the caller to pass the
> user_info which is only available in helper context:
> 
> static inline int rtdm_rt_capable(rtdm_user_info_t *user_info)
> {
>       XENO_ASSERT(RTDM, !xnpod_asynch_p(), return 0;);
> 
>       return (!xnpod_root_p() ||
>               (user_info && xnshadow_thread(user_info) != NULL));
> }

This is now correct in a Xenomai context. Thanks.

> 
> Pushed a corresponding patch.
> 
> Jan
> 


-- 
Philippe.



_______________________________________________
Xenomai-core mailing list
Xenomai-core@gna.org
https://mail.gna.org/listinfo/xenomai-core

Reply via email to