当前位置: 首页>>代码示例>>C++>>正文


C++ DatabaseConnection::start方法代码示例

本文整理汇总了C++中DatabaseConnection::start方法的典型用法代码示例。如果您正苦于以下问题:C++ DatabaseConnection::start方法的具体用法?C++ DatabaseConnection::start怎么用?C++ DatabaseConnection::start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DatabaseConnection的用法示例。


在下文中一共展示了DatabaseConnection::start方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: connections


//.........这里部分代码省略.........

                        // Disconnect the execution signal so if the old
                        // receiver is still around it won't keep getting
                        // signals
                        connection->disconnectQueue(
                            DatabaseConnection::EXECUTED);

                        // Rollback transaction if applicable
                        connection->call(Variant(),
                                         QueryEvent::CLEAN_STATE);
                    }

                } else if (currentRecord.expiry != 0
                           && currentRecord.expiry > std::time(nullptr)) {

                    // This connection has expired

                    // Lock this connection's mutex
                    currentConnection->mutex.lock();

                    // Check if this connection is in the process of shutting
                    // down or is busy with something
                    busy = currentConnection->busy
                            || !currentConnection->commands.empty();

                    // Unlock the mutex
                    currentConnection->mutex.unlock();

                    if (!busy) {
                        // Tell the connection to disconnect. We'll free memory
                        // after that is finished
                        if (!currentConnection->isStopping()) {

                            // Ensure this connection's signals are disconnected
                            currentConnection->disconnectQueue(
                                DatabaseConnection::EXECUTED);

                            // Connect to ourself. After the disconnect
                            // completes, we need to free the connection

                            currentConnection->connectQueue(
                                DatabaseConnection::EXECUTED, this);

                            currentConnection->call(Variant(currentRecord.uuid),
                                QueryEvent::DISCONNECT);
                        }

                        // Remove from the hash
                        this->connections.erase(currentConnection);

                        // Add to the disconnections hash
                        disconnectingConnections[currentRecord.uuid]
                                = currentConnection;
                    }
                }

                count++;
            }
        }

        if (connection == nullptr && count < maxConnections) {

            // Initialize new connection
            connection = mainConnection->clone(this);

            // Start new thread
            connection->start();
        }

        if (connection != nullptr) {
            record.expiry = timeout;
            record.uuid = UUID::makeUUID();
            record.receiver = receiver;
            this->connections[connection] = record;
        }

        if (connection == nullptr) {
            // Process any pending events
            Application::getInstance()->processEvents();

            // Also sleep for 30ms. There may not be events to process above
            // and we don't want to pin the cpu
            usleep(30 * 1000);
        }
    }

    if (receiver != nullptr) {

        // Lock mutex
        connection->mutex.lock();

        // Connect signal
        connection->connectQueue(DatabaseConnection::EXECUTED, receiver);

        // Unlock mutex
        connection->mutex.unlock();
    }

    return connection;
}
开发者ID:RabidSQL,项目名称:backend,代码行数:101,代码来源:DatabaseConnectionManager.cpp


注:本文中的DatabaseConnection::start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。