| 1628 | } |
| 1629 | |
| 1630 | void application_impl::dispatch() { |
| 1631 | #if defined(__linux__) |
| 1632 | { |
| 1633 | std::stringstream s; |
| 1634 | s << hex4(client_) << "_dispatch"; |
| 1635 | pthread_setname_np(pthread_self(), s.str().c_str()); |
| 1636 | } |
| 1637 | #endif |
| 1638 | const std::thread::id its_id = std::this_thread::get_id(); |
| 1639 | |
| 1640 | VSOMEIP_INFO << "Started thread " << hex4(client_) << "_dispatch, application '" << name_ << "', id " << std::hex << its_id |
| 1641 | #if defined(__linux__) |
| 1642 | << ", tid " << std::dec << static_cast<int>(syscall(SYS_gettid)) |
| 1643 | #endif |
| 1644 | ; |
| 1645 | |
| 1646 | std::unique_lock its_lock(handlers_mutex_); |
| 1647 | while (is_active_dispatcher(its_id)) { |
| 1648 | if (is_dispatching_ && handlers_.empty()) { |
| 1649 | dispatcher_condition_.wait(its_lock, [this] { return !is_dispatching_ || !handlers_.empty() || elapse_unactive_dispatchers_; }); |
| 1650 | |
| 1651 | // Maybe woken up from main dispatcher |
| 1652 | if (handlers_.empty() && !is_active_dispatcher(its_id)) { |
| 1653 | if (!is_dispatching_) { |
| 1654 | return; |
| 1655 | } |
| 1656 | elapsed_dispatchers_.insert(its_id); |
| 1657 | return; |
| 1658 | } |
| 1659 | } else { |
| 1660 | std::shared_ptr<sync_handler> its_handler; |
| 1661 | while (is_dispatching_ && is_active_dispatcher(its_id) && (its_handler = get_next_handler())) { |
| 1662 | invoke_handler(its_lock, its_handler); |
| 1663 | |
| 1664 | if (!is_dispatching_) |
| 1665 | return; |
| 1666 | |
| 1667 | reschedule_availability_handler(its_handler); |
| 1668 | reschedule_subscription_handler(its_handler); |
| 1669 | remove_elapsed_dispatchers(its_lock); |
| 1670 | } |
| 1671 | } |
| 1672 | } |
| 1673 | if (is_dispatching_) { |
| 1674 | elapsed_dispatchers_.insert(its_id); |
| 1675 | } |
| 1676 | dispatcher_condition_.notify_all(); |
| 1677 | |
| 1678 | VSOMEIP_INFO << "Stopped thread " << hex4(client_) << "_dispatch, application '" << name_ << "', id " << std::hex << its_id |
| 1679 | #if defined(__linux__) |
| 1680 | << ", tid " << std::dec << static_cast<int>(syscall(SYS_gettid)) |
| 1681 | #endif |
| 1682 | ; |
| 1683 | } |
| 1684 | |
| 1685 | std::shared_ptr<application_impl::sync_handler> application_impl::get_next_handler() { |
| 1686 | std::shared_ptr<sync_handler> its_next_handler; |
no test coverage detected