fdbus event loop and thread relationship

fdbus contains two event loop implementations, CFdEventLoop and CThreadEventLoop, which can be seen through the source code. CBaseWorker is a thread class. Speaking of event loops, threads are generally inseparable. Except for qt, the qt framework guarantees all QObject objects under the thread. Sharing an event queue, each QObject object has thread dependency, that is, which thread it belongs to.

CBaseWorker is a thread class, and the event loop needs to be implemented in this thread class.

According to my current understanding of the fdbus code, CBaseWorker uses the CThreadEventLoop event loop for the following reasons. The parameter flag is not set by default and uses the default value. To understand it from this perspective, CThreadEventLoop is used:

bool CBaseWorker::init(uint32_t flag)
{
    if (mEventLoop)
    {
        return true;
    }
    if (flag & FDB_WORKER_ENABLE_FD_LOOP)
    {
        mEventLoop = new CFdEventLoop();
    }
    else
    {
        mEventLoop = new CThreadEventLoop();
    }
    mNormalJobQueue.eventLoop(mEventLoop);
    mUrgentJobQueue.eventLoop(mEventLoop);
    if (!mEventLoop->init(this))
    {
        LOG_E("CBaseWorker: fail to initialize event loop!\n");
        return false;
    }
    return true;
}


But I analyzed the message sending code. I didn’t find anything related to the CThreadEventLoop event loop in the message receiving process. Instead, I found the message receiving code in CFdEventLoop. From the code point of view, it was conflicting and confusing. Okay, now I still don’t understand how message loop reception is implemented.

Guess you like

Origin blog.csdn.net/iqanchao/article/details/133384110