コード例 #1
0
ファイル: MongoDatabase.cpp プロジェクト: Fantasticer/Astron
    void run_thread()
    {
        unique_lock<mutex> guard(m_lock);

        DBClientBase *client = new_connection();

        while(true) {
            if(!client->isStillConnected()) {
                m_log->error() << "A thread lost its connection, reconnecting..." << endl;
                delete client;
                client = new_connection();
            }

            if(m_operation_queue.size() > 0) {
                DBOperation *op = m_operation_queue.front();
                m_operation_queue.pop();

                guard.unlock();
                handle_operation(client, op);
                guard.lock();
            } else if(m_shutdown) {
                break;
            } else {
                m_cv.wait(guard);
            }
        }

        delete client;
    }