qinguoyi / TinyWebServer

:fire: Linux下C++轻量级WebServer服务器
Apache License 2.0
16.89k stars 3.96k forks source link

sql_connect_pool.cpp中的GetConnection函数的一个问题? #269

Open PPhoss opened 8 months ago

PPhoss commented 8 months ago
MYSQL *connection_pool::GetConnection()
{
    MYSQL *con = NULL;

    if (0 == connList.size())
        return NULL;

    reserve.wait();

    lock.lock();

    con = connList.front();
    connList.pop_front();

    --m_FreeConn;
    ++m_CurConn;

    lock.unlock();
    return con;
}

大佬们,我想问一下,这个函数中为什么要做if(0==connList.size())这个判断?如果做了这个判断不久直接返回了吗,就不会有后面的reserve.wait()等待了呀?