| 1268 | |
| 1269 | |
| 1270 | void ExtEngineManager::closeAttachment(thread_db* tdbb, Attachment* attachment) |
| 1271 | { |
| 1272 | EnginesMap enginesCopy; |
| 1273 | |
| 1274 | { // scope |
| 1275 | ReadLockGuard readGuard(enginesLock, FB_FUNCTION); |
| 1276 | |
| 1277 | EnginesMap::Accessor accessor(&engines); |
| 1278 | for (bool found = accessor.getFirst(); found; found = accessor.getNext()) |
| 1279 | enginesCopy.put(accessor.current()->first, accessor.current()->second); |
| 1280 | } |
| 1281 | |
| 1282 | EngineCheckout cout(tdbb, FB_FUNCTION, EngineCheckout::UNNECESSARY); |
| 1283 | |
| 1284 | EnginesMap::Accessor accessor(&enginesCopy); |
| 1285 | for (bool found = accessor.getFirst(); found; found = accessor.getNext()) |
| 1286 | { |
| 1287 | IExternalEngine* engine = accessor.current()->second; |
| 1288 | EngineAttachmentInfo* attInfo = getEngineAttachment(tdbb, engine, true); |
| 1289 | |
| 1290 | if (attInfo) |
| 1291 | { |
| 1292 | { // scope |
| 1293 | ContextManager<IExternalFunction> ctxManager(tdbb, attInfo, attInfo->adminCharSet); |
| 1294 | FbLocalStatus status; |
| 1295 | engine->closeAttachment(&status, attInfo->context); //// FIXME: log status |
| 1296 | |
| 1297 | // Check whether a non-SYSTEM engine is used by other attachments. |
| 1298 | // If no one uses, release it. |
| 1299 | if (engine != SystemEngine::INSTANCE) |
| 1300 | { |
| 1301 | bool close = true; |
| 1302 | WriteLockGuard writeGuard(enginesLock, FB_FUNCTION); |
| 1303 | |
| 1304 | EnginesAttachmentsMap::Accessor ea_accessor(&enginesAttachments); |
| 1305 | for (bool ea_found = ea_accessor.getFirst(); ea_found; ea_found = ea_accessor.getNext()) |
| 1306 | { |
| 1307 | if (ea_accessor.current()->first.engine == engine) |
| 1308 | { |
| 1309 | close = false; // engine is in use, no need to release |
| 1310 | break; |
| 1311 | } |
| 1312 | } |
| 1313 | |
| 1314 | if (close) |
| 1315 | { |
| 1316 | if (engines.remove(accessor.current()->first)) // If engine has already been deleted - nothing to do |
| 1317 | PluginManagerInterfacePtr()->releasePlugin(engine); |
| 1318 | } |
| 1319 | } |
| 1320 | } |
| 1321 | |
| 1322 | delete attInfo; |
| 1323 | } |
| 1324 | } |
| 1325 | } |
| 1326 | |
| 1327 |
no test coverage detected