Skip to contentSkip to conversation

Calling rt_task_shadow from a POSIX thread with --enable-dlopen-skins

Xenomai-help Simon Leonard 2 participants 2 messages Apr 25, 2011

lore
Share & tools
lore
#0 lore 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

#1 lore raw
Quoted 3 lines · Simon Leonard

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.

Mmmm. Normally, without --enable-dlopen-skins, only the main thread is automatically made real-time.

Quoted 3 lines

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?

It works, but, there are services in the POSIX skin which will only work if the thread is a posix skin thread, not if it is a native skin thread. Anyway, you can use pthread_setschedparam instead of rt_task_shadow.

Signature · 1 line
                                                                Gilles.