| 451 | } |
| 452 | |
| 453 | void rt_thread_handle_sig(rt_bool_t clean_state) |
| 454 | { |
| 455 | rt_base_t level; |
| 456 | |
| 457 | rt_thread_t tid = rt_thread_self(); |
| 458 | struct siginfo_node *si_node; |
| 459 | |
| 460 | level = rt_spin_lock_irqsave(&_thread_signal_lock); |
| 461 | if (tid->sig_pending & tid->sig_mask) |
| 462 | { |
| 463 | /* if thread is not waiting for signal */ |
| 464 | if (!(RT_SCHED_CTX(tid).stat & RT_THREAD_STAT_SIGNAL_WAIT)) |
| 465 | { |
| 466 | while (tid->sig_pending & tid->sig_mask) |
| 467 | { |
| 468 | int signo, error; |
| 469 | rt_sighandler_t handler; |
| 470 | |
| 471 | si_node = (struct siginfo_node *)tid->si_list; |
| 472 | if (!si_node) break; |
| 473 | |
| 474 | /* remove this sig info node from list */ |
| 475 | if (si_node->list.next == RT_NULL) |
| 476 | tid->si_list = RT_NULL; |
| 477 | else |
| 478 | tid->si_list = (void *)rt_slist_entry(si_node->list.next, struct siginfo_node, list); |
| 479 | |
| 480 | signo = si_node->si.si_signo; |
| 481 | handler = tid->sig_vectors[signo]; |
| 482 | tid->sig_pending &= ~sig_mask(signo); |
| 483 | rt_spin_unlock_irqrestore(&_thread_signal_lock, level); |
| 484 | |
| 485 | LOG_D("handle signal: %d, handler 0x%08x", signo, handler); |
| 486 | if (handler) handler(signo); |
| 487 | |
| 488 | level = rt_spin_lock_irqsave(&_thread_signal_lock); |
| 489 | error = -RT_EINTR; |
| 490 | |
| 491 | rt_mp_free(si_node); /* release this siginfo node */ |
| 492 | /* set errno in thread tcb */ |
| 493 | tid->error = error; |
| 494 | } |
| 495 | |
| 496 | /* whether clean signal status */ |
| 497 | if (clean_state == RT_TRUE) |
| 498 | { |
| 499 | RT_SCHED_CTX(tid).stat &= ~RT_THREAD_STAT_SIGNAL; |
| 500 | } |
| 501 | else |
| 502 | { |
| 503 | rt_spin_unlock_irqrestore(&_thread_signal_lock, level); |
| 504 | return; |
| 505 | } |
| 506 | } |
| 507 | } |
| 508 | rt_spin_unlock_irqrestore(&_thread_signal_lock, level); |
| 509 | } |
| 510 |
no test coverage detected