All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Leonard <sleonard@domain.hid>
To: xenomai@xenomai.org
Subject: [Xenomai-help] Calling rt_task_shadow from a POSIX thread with --enable-dlopen-skins
Date: Sun, 24 Apr 2011 22:20:17 -0400	[thread overview]
Message-ID: <4DB4DA61.9070906@domain.hid> (raw)

I have code based on the POSIX skin. For a (python related) reason, I 
had to re-compile Xenomai with --enable-dlopen-skins. The result is that 
unless I call rt_task_shadow, my threads don't work like they used to.

Although I *think* my code works by mixing rt_task_shadow with the POSIX 
skin I'm not convinced that it is legit. Can anybody advise?

Essentially, I need a CAN object that is instantiated and configured 
from main(). Then that object (pointer) is passed to a thread that 
Read/Write from/to it. Here a simplified version.

A few questions:
1) Can I mix rt_task_shadow from a thread created from POSIX skin?
2) If yes, is there limitations to POSIX function? For example, are the 
attributes of any pthread_attr_t discarded after calling rt_task_shadow?
4) How about a thread that doesn't use RTDM? Will it have "RT" latencies 
or rt_task_shadow must be called for that too?
4) Is it just better to port everything to native skin?

class CANdevice{

   RT_TASK task; // Added this for calling rt_task_shadow

public:

   CANdevice(){
     // add this block to Read/Write from main()
     if( rt_task_self() == NULL )
       { rt_task_shadow( &task, "can", prio, flags); }
   }

   void Configure(){ /* Read()/Write() */ }
   void Read() { /* rt_dev_recv  */
   void Write(){ /* rt_dev_send */

};

void* thread( void* argv ){

   CANdevice* can = (CANdevice*)argv;

   /* add this block to Read/Write from thread(void*) */
   RT_TASK task;
   if( rt_task_self() == NULL ){
     printf( "NOT A XENOMAI TASK\n" );
     rt_task_shadow(&task, "thread", prio, flags );
   }

   pthread_make_periodic_np ( pthread_self(), &starttp, &periodtp );

   while(1){
     can->Read();
     can->Write();
     pthread_wait_np(&overruns_r);
   }

   return NULL;
}

int main(){
   CANdevice can;
   can.Configure(); // main() must be Xenomai task to use RTDM

   pthread_t tid;
   pthread_attr_t attr;
   struct sched_param param;
   param.sched_priority = prio;

   // attributes
   pthread_attr_init( &attr );
   pthread_attr_setschedpolicy( &attr, SCHED_FIFO );
   pthread_attr_setschedparam( &attr, &param );

   // thread must be Xenomai task to use RTDM
   pthread_create( &tid, &attr, thread, (void*)&can );

}

/sl


             reply	other threads:[~2011-04-25  2:20 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-04-25  2:20 Simon Leonard [this message]
2011-04-25  6:47 ` [Xenomai-help] Calling rt_task_shadow from a POSIX thread with --enable-dlopen-skins Gilles Chanteperdrix

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4DB4DA61.9070906@domain.hid \
    --to=sleonard@domain.hid \
    --cc=xenomai@xenomai.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.