| 960 | } |
| 961 | |
| 962 | void ConnectionsPool::putConnection(thread_db* tdbb, Connection* conn) |
| 963 | { |
| 964 | fb_assert(conn->getConnPool() == this); |
| 965 | |
| 966 | Connection* oldConn = NULL; |
| 967 | Firebird::RefPtr<IdleTimer> timer; |
| 968 | |
| 969 | if (m_maxCount > 0) |
| 970 | { |
| 971 | MutexLockGuard guard(m_mutex, FB_FUNCTION); |
| 972 | |
| 973 | Data* item = conn->getPoolData(); |
| 974 | #ifdef EDS_DEBUG |
| 975 | if (!verifyPool()) |
| 976 | { |
| 977 | string str; |
| 978 | str.printf("Before put Item 0x%08X into pool\n", item); |
| 979 | printPool(str); |
| 980 | gds__log("Procces ID %d: connections pool is corrupted\n%s", getpid(), str.c_str()); |
| 981 | } |
| 982 | #endif |
| 983 | |
| 984 | if (item->m_lastUsed) |
| 985 | { |
| 986 | // Item was already put into idle list |
| 987 | fb_assert(item->m_connPool == this); |
| 988 | return; |
| 989 | } |
| 990 | |
| 991 | if (m_allCount > m_maxCount) |
| 992 | { |
| 993 | Data* oldest = removeOldest(); |
| 994 | if (oldest == item) |
| 995 | { |
| 996 | #ifdef EDS_DEBUG |
| 997 | string str; |
| 998 | str.printf("Item 0x%08X to put into pool is oldest", item); |
| 999 | gds__log("Procces ID %d: %s", getpid(), str.c_str()); |
| 1000 | #endif |
| 1001 | m_allCount++; |
| 1002 | oldest = removeOldest(); |
| 1003 | } |
| 1004 | |
| 1005 | if (oldest) |
| 1006 | oldConn = oldest->m_conn; |
| 1007 | } |
| 1008 | |
| 1009 | if (item->m_lastUsed) |
| 1010 | { |
| 1011 | FB_SIZE_T pos; |
| 1012 | fb_assert(m_idleArray.find(*item, pos)); |
| 1013 | |
| 1014 | #ifdef EDS_DEBUG |
| 1015 | const bool ok = verifyPool(); |
| 1016 | string str; |
| 1017 | str.printf("Idle item 0x%08X put back into pool. Pool is %s", item, ok ? "OK" : "corrupted\n"); |
| 1018 | |
| 1019 | if (!ok) |
no test coverage detected