Exemplo n.º 1
0
int main(void)
{
	unsigned long hrttsk_name = nam2num("HRTTSK");
	struct sched_param mysched;

	mysched.sched_priority = sched_get_priority_max(SCHED_FIFO);
	if( sched_setscheduler( 0, SCHED_FIFO, &mysched ) == -1 ) {
		puts("ERROR IN SETTING THE SCHEDULER");
		perror("errno");
		exit(0);
 	}
 	if (!(hrttsk = rt_task_init(hrttsk_name, 1, 0, 0))) {
		printf("CANNOT INIT TESTB MASTER TASK\n");
		exit(1);
	}

	rt_set_usp_flags_mask(FORCE_SOFT);
	rt_task_suspend(hrttsk);
	printf("BACKGROUND REAL TIME TASK IS HARD .....\n");
	mlockall(MCL_CURRENT | MCL_FUTURE);

	rt_make_hard_real_time();
	while(rt_is_hard_real_time(hrttsk)) {
		rt_task_wait_period();
	}
	printf("..... BACKGROUND REAL TIME TASK IS SOFT NOW, YOU CAN KILL IT BY HAND\n");
	rt_task_delete(hrttsk);
	while(1) { sleep(3); printf("BACKGROUND PROCESS STILL RUNNING\n"); }
}
void *ThreadImplLxrt35::runThread(void *arg)
{
  ThreadImplLxrt35 *self = static_cast<ThreadImplLxrt35*>(arg);

  if (self->m_rt_start_sync == NULL)
  {
    // Technically, this can never happen because this condition is
    // already checked in the Start() function. But who knows!
    PRINTF("ERROR: NULL thread start barrier!\n");
  }
  else
  {
    self->m_rt_task = rt_task_init(getpid() + pthread_self_rt(), abs(self->m_priority),
                                   DEFAULT_STACK_SIZE, 0);
    if (self->m_rt_task == NULL)
    {
      PRINTF("ERROR: Cannot initialize LXRT task %lu!\n", self->m_thread_id);
      PRINTF("       Probably another thread with the same name already exists.\n");

      // Let the thread, which started us, continue!
      pthread_barrier_wait_rt(self->m_rt_start_sync);
    }
    else
    {
      if (self->m_priority < 0)
      {
        rt_make_hard_real_time();
        if (!rt_is_hard_real_time(rt_buddy()))
        {
          PRINTF("ERROR: Setting thread %lu to hard real-time failed!\n", self->m_thread_id);
        }
        else
        {
          // Everything worked as expected, so no message here.
        }
      }
      else
      {
        // This is a soft realtime thread, so nothing additional has
        // to be done here.
      }

      pthread_barrier_wait_rt(self->m_rt_start_sync);

      self->m_thread->runThread();

      // Remark: It does not hurt to call this in a soft realtime
      // thread, so just skip the hard realtime test.
      rt_make_soft_real_time();
    }
  }

  return NULL;
}
Exemplo n.º 3
0
static inline void send_to_mbx(FILE *fs, struct LOGMSG msg)
{
	RT_TASK *buddy;

	msg.msg[MAX_MSG_SIZE - 1] = 0;
	if (++msg.nch >= (MAX_MSG_SIZE - 1)) {
		msg.nch = MAX_MSG_SIZE - 1;
	}
	if (!(buddy = rt_buddy()) || (buddy && !rt_is_hard_real_time(buddy))) {
		fprintf(stderr, msg.msg);
	} else {
		msg.fs = fs;
		rt_mbx_send_if(logmbx, &msg, sizeof(int) + sizeof(FILE *) + msg.nch);
	}
}
void *ThreadImplLxrt33::runThread(void *arg)
{
  ThreadImplLxrt33 *self = static_cast<ThreadImplLxrt33*>(arg);

  self->m_rt_task = rt_task_init(getpid() + pthread_self_rt(), abs(self->m_priority),
                                 DEFAULT_STACK_SIZE, 0);
  if (self->m_rt_task == NULL)
  {
    PRINTF("ERROR: Cannot initialize LXRT task %lu!\n", self->m_thread_id);
    PRINTF("       Probably another thread with the same name already exists.\n");
  }
  else
  {
    rt_task_use_fpu(self->m_rt_task, 1);

    if (self->m_priority < 0)
    {
      rt_make_hard_real_time();
      if (!rt_is_hard_real_time(rt_buddy()))
      {
        PRINTF("ERROR: Setting thread %lu to hard real-time failed!\n", self->m_thread_id);
      }
      else
      {
        // Everything worked as expected, so no message here.
      }
    }
    else
    {
      // This is a soft realtime thread, so nothing additional has to
      // be done here.
    }

    self->m_thread->runThread();

    rt_make_soft_real_time();

    // TODO: Check if this is correct. The RTAI 3.5 and 3.8
    // implementations leave this to a call to join().
    rt_task_delete(self->m_rt_task);
    self->m_rt_task = NULL;
  }

  return NULL;
}
Exemplo n.º 5
0
 INTERNAL_QUAL int rtos_task_get_scheduler(const RTOS_TASK* t) {
     if ( rt_is_hard_real_time( t->rtaitask ) )
         return SCHED_LXRT_HARD;
     return SCHED_LXRT_SOFT;
 }