本文整理汇总了C++中DatabaseConnection::disconnectQueue方法的典型用法代码示例。如果您正苦于以下问题:C++ DatabaseConnection::disconnectQueue方法的具体用法?C++ DatabaseConnection::disconnectQueue怎么用?C++ DatabaseConnection::disconnectQueue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DatabaseConnection
的用法示例。
在下文中一共展示了DatabaseConnection::disconnectQueue方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: connections
/**
*
* Reserves a database connection. Until this is freed, it will not be re-used.
*
* @param timeout The minimum amount of time to use this connection in seconds
* @param receiver The object which we'll send any data to
*
* @return A UUID for this connection
*/
DatabaseConnection *DatabaseConnectionManager::reserveDatabaseConnectionObj(
int timeout, SmartObject *receiver)
{
ConnectionRecord record, currentRecord;
DatabaseConnection *connection = nullptr, *currentConnection;
int count;
bool running, busy;
if (timeout != 0) {
// Expiry = unixtime + whatever timeout started as
timeout += std::time(nullptr);
}
while (connection == nullptr) {
// Reset counter
count = 0;
// Iterate connections
Connections connections(this->connections);
for (Connections::iterator it = connections.begin();
it != connections.end(); ++it) {
currentConnection = it->first;
currentRecord = it->second;
if (currentRecord.expiry != 0) {
// This connection has an expiry. No expiry indicates that it is
// a reserved connection that should not be re-assigned.
if (connection == nullptr) {
// Lock this connection's mutex
currentConnection->mutex.lock();
// Check if this connection is in the process of shutting
// down or is busy with something (or has pending queries)
busy = currentConnection->busy
|| !currentConnection->commands.empty();
// Unlock the mutex
currentConnection->mutex.unlock();
if (currentConnection->isStopping() && !busy) {
// Re-use this connection
connection = currentConnection;
// 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);
//.........这里部分代码省略.........