| 8994 | |
| 8995 | |
| 8996 | static THREAD_ENTRY_DECLARE shutdown_thread(THREAD_ENTRY_PARAM arg) |
| 8997 | { |
| 8998 | /************************************** |
| 8999 | * |
| 9000 | * s h u t d o w n _ t h r e a d |
| 9001 | * |
| 9002 | ************************************** |
| 9003 | * |
| 9004 | * Functional description |
| 9005 | * Shutdown the engine. |
| 9006 | * |
| 9007 | **************************************/ |
| 9008 | Semaphore* const semaphore = static_cast<Semaphore*>(arg); |
| 9009 | |
| 9010 | bool success = true; |
| 9011 | MemoryPool& pool = *getDefaultMemoryPool(); |
| 9012 | AttachmentsRefHolder* const attachments = FB_NEW_POOL(pool) AttachmentsRefHolder(pool); |
| 9013 | |
| 9014 | try |
| 9015 | { |
| 9016 | { // scope |
| 9017 | MutexLockGuard guard(databases_mutex, FB_FUNCTION); |
| 9018 | |
| 9019 | for (Database* dbb = databases; dbb; dbb = dbb->dbb_next) |
| 9020 | { |
| 9021 | if (!(dbb->dbb_flags & DBB_bugcheck)) |
| 9022 | { |
| 9023 | Sync dbbGuard(&dbb->dbb_sync, FB_FUNCTION); |
| 9024 | dbbGuard.lock(SYNC_EXCLUSIVE); |
| 9025 | |
| 9026 | for (Attachment* att = dbb->dbb_attachments; att; att = att->att_next) |
| 9027 | attachments->add(att->getStable()); |
| 9028 | } |
| 9029 | } |
| 9030 | // No need in databases_mutex any more |
| 9031 | } |
| 9032 | |
| 9033 | // Shutdown existing attachments |
| 9034 | success = success && shutdownAttachments(attachments, isc_att_shut_engine); |
| 9035 | |
| 9036 | HalfStaticArray<Database*, 32> dbArray(pool); |
| 9037 | { // scope |
| 9038 | MutexLockGuard guard(databases_mutex, FB_FUNCTION); |
| 9039 | |
| 9040 | for (Database* dbb = databases; dbb; dbb = dbb->dbb_next) |
| 9041 | dbArray.push(dbb); |
| 9042 | |
| 9043 | // No need in databases_mutex any more |
| 9044 | } |
| 9045 | |
| 9046 | for (unsigned n = 0; n < dbArray.getCount(); ++n) |
| 9047 | JRD_shutdown_database(dbArray[n], SHUT_DBB_RELEASE_POOLS); |
| 9048 | |
| 9049 | // Extra shutdown operations |
| 9050 | Service::shutdownServices(); |
| 9051 | TRA_shutdown_sweep(); |
| 9052 | } |
| 9053 | catch (const Exception& ex) |
no test coverage detected