mfavant / tubekit

NEW PROJECT https://github.com/crust-hub/avant
MIT License
0 stars 0 forks source link

should be optimize #6

Closed gaowanlu closed 10 months ago

gaowanlu commented 10 months ago

should be optimize using condition vaiable

template <typename THREAD, typename TASK>
        void task_dispatcher<THREAD, TASK>::handle(TASK *m_task)
        {
            singleton<logger>::instance()->debug(__FILE__, __LINE__, "task dispatcher handle task");
            thread_pool<THREAD, TASK> *pool = singleton<thread_pool<THREAD, TASK>>::instance();
            if (pool->get_idle_thread_numbers() > 0)
            {
                pool->assign(m_task);
            }
            else
            {
                m_mutex.lock();
                m_tasks.push_front(m_task); // If there are no free threads, they are put into the list first
                m_mutex.unlock();
                singleton<logger>::instance()->debug(__FILE__, __LINE__, "all threads are busy");
            }
        }