| 334 | | mb_initialized = 1; |
|---|
| 335 | | |
|---|
| 336 | | if (pthread_create(&mb_writer_thread, NULL, &mb_thread_func, (void *)this) != 0) |
|---|
| | 334 | |
|---|
| | 335 | #if DEBUG_MESSAGE_BUFFER_REALTIME |
|---|
| | 336 | /* Get the client thread to run as an RT-FIFO |
|---|
| | 337 | scheduled thread of appropriate priority. |
|---|
| | 338 | */ |
|---|
| | 339 | pthread_attr_t attributes; |
|---|
| | 340 | struct sched_param rt_param; |
|---|
| | 341 | pthread_attr_init(&attributes); |
|---|
| | 342 | int res; |
|---|
| | 343 | if ((res = pthread_attr_setinheritsched(&attributes, PTHREAD_EXPLICIT_SCHED))) { |
|---|
| | 344 | fprintf(stderr, "Cannot request explicit scheduling for RT thread %d %s\n", res, strerror(res)); |
|---|
| | 345 | return -1; |
|---|
| | 346 | } |
|---|
| | 347 | if ((res = pthread_attr_setdetachstate(&attributes, PTHREAD_CREATE_JOINABLE))) { |
|---|
| | 348 | fprintf(stderr, "Cannot request joinable thread creation for RT thread %d %s\n", res, strerror(res)); |
|---|
| | 349 | return -1; |
|---|
| | 350 | } |
|---|
| | 351 | if ((res = pthread_attr_setscope(&attributes, PTHREAD_SCOPE_SYSTEM))) { |
|---|
| | 352 | fprintf(stderr, "Cannot set scheduling scope for RT thread %d %s\n", res, strerror(res)); |
|---|
| | 353 | return -1; |
|---|
| | 354 | } |
|---|
| | 355 | |
|---|
| | 356 | if ((res = pthread_attr_setschedpolicy(&attributes, SCHED_FIFO))) { |
|---|
| | 357 | |
|---|
| | 358 | //if ((res = pthread_attr_setschedpolicy(&attributes, SCHED_RR))) { |
|---|
| | 359 | fprintf(stderr, "Cannot set FIFO scheduling class for RT thread %d %s\n", res, strerror(res)); |
|---|
| | 360 | return -1; |
|---|
| | 361 | } |
|---|
| | 362 | |
|---|
| | 363 | memset(&rt_param, 0, sizeof(rt_param)); |
|---|
| | 364 | rt_param.sched_priority = DEBUG_MESSAGE_BUFFER_REALTIME_PRIO; |
|---|
| | 365 | |
|---|
| | 366 | if ((res = pthread_attr_setschedparam(&attributes, &rt_param))) { |
|---|
| | 367 | fprintf(stderr, "Cannot set scheduling priority for RT thread %d %s\n", res, strerror(res)); |
|---|
| | 368 | return -1; |
|---|
| | 369 | } |
|---|
| | 370 | |
|---|
| | 371 | if ((res = pthread_create(&mb_writer_thread, &attributes, mb_thread_func, (void *)this))) { |
|---|
| | 372 | fprintf(stderr, "Cannot set create thread %d %s\n", res, strerror(res)); |
|---|
| | 373 | mb_initialized = 0; |
|---|
| | 374 | } else { |
|---|
| | 375 | mb_initialized = 1; |
|---|
| | 376 | } |
|---|
| | 377 | #else |
|---|
| | 378 | if (pthread_create(&mb_writer_thread, NULL, &mb_thread_func, (void *)this) != 0) { |
|---|