Changeset 213 in flair-src for trunk/lib/FlairCore/src/Thread_impl.cpp


Ignore:
Timestamp:
Jan 30, 2018, 5:47:12 PM (7 years ago)
Author:
Sanahuja Guillaume
Message:

thread stack size rework
add Matrix class

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/lib/FlairCore/src/Thread_impl.cpp

    r206 r213  
    3636using namespace flair::core;
    3737
    38 Thread_impl::Thread_impl(Thread *self, uint8_t priority) {
     38Thread_impl::Thread_impl(Thread *self, uint8_t priority,uint32_t stackSize) {
    3939  isRunning = false;
    4040  tobestopped = false;
    4141  is_suspended = false;
    4242  period_set = false;
     43  this->stackSize = stackSize;
    4344
    4445  this->self = self;
     
    7879void Thread_impl::Start(void) {
    7980  int status;
    80         char errorMsg[256];
    81 
    8281  isRunning = true;
    8382  tobestopped = false;
    8483  is_suspended = false;
    8584
     85 Printf("Starting thread %s (priority=%i, stack size=%i bytes)\n",self->ObjectName().c_str(), priority,stackSize);
    8686#ifdef __XENO__
    8787  string th_name =TH_NAME;
    8888
    89 #ifdef RT_STACK_SIZE
    90   status = rt_task_create(&task_rt, th_name.c_str(), RT_STACK_SIZE,
     89  status = rt_task_create(&task_rt, th_name.c_str(), stackSize,
    9190                          (int)priority, T_JOINABLE);
    92 #else
    93   status =
    94       rt_task_create(&task_rt, th_name.c_str(), 0, (int)priority, T_JOINABLE);
    95 #endif // RT_STACK_SIZE
    96   if (status != 0) {
     91
     92  if (status != 0) {
     93    char errorMsg[256];
    9794    self->Err("rt_task_create error (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg)));
    9895  } else {
     
    10299  status = rt_task_start(&task_rt, &main_rt, (void *)this);
    103100  if (status != 0) {
     101    char errorMsg[256];
    104102    self->Err("rt_task_start error (%s)\n", strerror_r(-status, errorMsg, sizeof(errorMsg)));
    105103  } else {
     
    115113  }
    116114
    117 #ifdef NRT_STACK_SIZE
    118   if (pthread_attr_setstacksize(&attr, NRT_STACK_SIZE) != 0) {
     115  if (pthread_attr_setstacksize(&attr, stackSize) != 0) {
    119116    self->Err("Error pthread_attr_setstacksize\n");
    120117  }
    121 #endif // NRT_STACK_SIZE
    122118
    123119  if (pthread_attr_setinheritsched(&attr, PTHREAD_EXPLICIT_SCHED) != 0) {
     
    320316
    321317void Thread_impl::PrintStats(void) {
     318  Printf("Stopping thread %s\n", self->ObjectName().c_str());
    322319#ifdef __XENO__
    323320  RT_TASK_INFO info;
     
    333330  if(last!=0)
    334331#endif
    335     { Printf("Thread::%s :\n", self->ObjectName().c_str());
     332    {
    336333    if(period_set) {Printf("    period (ns): %lld\n", period);}}
    337334#ifdef __XENO__
     
    365362  if (isRunning == true) {
    366363    int status;
    367                 char errorMsg[256];
    368 
     364 
    369365#ifdef __XENO__
    370366    status = rt_task_join(&task_rt);
     
    372368    status = pthread_join(task_nrt, NULL);
    373369#endif
    374     if (status != 0)
     370    if (status != 0) {
     371      char errorMsg[256];
    375372      self->Err("error %s\n", strerror_r(-status, errorMsg, sizeof(errorMsg)));
     373    }
    376374    isRunning = false;
    377375  }
Note: See TracChangeset for help on using the changeset viewer.