* @ingroup group_thread_management * * @brief This function can be used to send any signal to any thread. * * @param tid is a pointer to the thread that receives the signal. * * @param sig is a specific signal value (range: 0 ~ RT_SIG_MAX). * * @return Return the operation status. When the return value is RT_EOK, the operation is successful. * If the return value is a
| 591 | * If the return value is any other values, it means that the signal send failed. |
| 592 | */ |
| 593 | int rt_thread_kill(rt_thread_t tid, int sig) |
| 594 | { |
| 595 | siginfo_t si; |
| 596 | rt_base_t level; |
| 597 | struct siginfo_node *si_node; |
| 598 | |
| 599 | RT_ASSERT(tid != RT_NULL); |
| 600 | if (!sig_valid(sig)) return -RT_EINVAL; |
| 601 | |
| 602 | LOG_I("send signal: %d", sig); |
| 603 | si.si_signo = sig; |
| 604 | si.si_code = SI_USER; |
| 605 | si.si_value.sival_ptr = RT_NULL; |
| 606 | |
| 607 | level = rt_spin_lock_irqsave(&_thread_signal_lock); |
| 608 | if (tid->sig_pending & sig_mask(sig)) |
| 609 | { |
| 610 | /* whether already emits this signal? */ |
| 611 | struct rt_slist_node *node; |
| 612 | struct siginfo_node *entry; |
| 613 | |
| 614 | si_node = (struct siginfo_node *)tid->si_list; |
| 615 | if (si_node) |
| 616 | node = (struct rt_slist_node *)&si_node->list; |
| 617 | else |
| 618 | node = RT_NULL; |
| 619 | |
| 620 | /* update sig info */ |
| 621 | for (; (node) != RT_NULL; node = node->next) |
| 622 | { |
| 623 | entry = rt_slist_entry(node, struct siginfo_node, list); |
| 624 | if (entry->si.si_signo == sig) |
| 625 | { |
| 626 | memcpy(&(entry->si), &si, sizeof(siginfo_t)); |
| 627 | rt_spin_unlock_irqrestore(&_thread_signal_lock, level); |
| 628 | return 0; |
| 629 | } |
| 630 | } |
| 631 | } |
| 632 | rt_spin_unlock_irqrestore(&_thread_signal_lock, level); |
| 633 | |
| 634 | si_node = (struct siginfo_node *) rt_mp_alloc(_siginfo_pool, 0); |
| 635 | if (si_node) |
| 636 | { |
| 637 | rt_slist_init(&(si_node->list)); |
| 638 | memcpy(&(si_node->si), &si, sizeof(siginfo_t)); |
| 639 | |
| 640 | level = rt_spin_lock_irqsave(&_thread_signal_lock); |
| 641 | |
| 642 | if (tid->si_list) |
| 643 | { |
| 644 | struct siginfo_node *si_list; |
| 645 | |
| 646 | si_list = (struct siginfo_node *)tid->si_list; |
| 647 | rt_slist_append(&(si_list->list), &(si_node->list)); |
| 648 | } |
| 649 | else |
| 650 | { |
no test coverage detected