| 729 | |
| 730 | |
| 731 | bool SDW_rollover_to_shadow(thread_db* tdbb, jrd_file* file, const bool inAst) |
| 732 | { |
| 733 | /************************************** |
| 734 | * |
| 735 | * S D W _ r o l l o v e r _ t o _ s h a d o w |
| 736 | * |
| 737 | ************************************** |
| 738 | * |
| 739 | * Functional description |
| 740 | * |
| 741 | **************************************/ |
| 742 | SET_TDBB(tdbb); |
| 743 | Database* dbb = tdbb->getDatabase(); |
| 744 | |
| 745 | PageSpace* pageSpace = dbb->dbb_page_manager.findPageSpace(DB_PAGE_SPACE); |
| 746 | if (file != pageSpace->file) |
| 747 | return true; |
| 748 | |
| 749 | SyncLockGuard guard(&dbb->dbb_shadow_sync, SYNC_EXCLUSIVE, "SDW_rollover_to_shadow"); |
| 750 | |
| 751 | SLONG sdw_update_flags = SDW_rollover; |
| 752 | |
| 753 | // If our attachment is already purged and an error comes from |
| 754 | // CCH_fini(), then consider us accessing the shadow exclusively. |
| 755 | // LCK_update_shadow locking isn't going to work anyway. The below |
| 756 | // code must be executed for valid active attachments only. |
| 757 | |
| 758 | AutoPtr<Lock> update_lock; |
| 759 | |
| 760 | if (tdbb->getAttachment()) |
| 761 | { |
| 762 | update_lock = FB_NEW_RPT(*tdbb->getDefaultPool(), 0) |
| 763 | Lock(tdbb, sizeof(SLONG), LCK_update_shadow); |
| 764 | update_lock->setKey(-1); |
| 765 | |
| 766 | LCK_lock(tdbb, update_lock, LCK_EX, LCK_NO_WAIT); |
| 767 | |
| 768 | if (update_lock->lck_physical != LCK_EX || |
| 769 | file != pageSpace->file || !SDW_lck_update(tdbb, sdw_update_flags)) |
| 770 | { |
| 771 | LCK_release(tdbb, update_lock); |
| 772 | LCK_lock(tdbb, update_lock, LCK_SR, LCK_NO_WAIT); |
| 773 | while (update_lock->lck_physical != LCK_SR) |
| 774 | { |
| 775 | if (dbb->dbb_ast_flags & DBB_get_shadows) |
| 776 | break; |
| 777 | if ((file != pageSpace->file ) || !dbb->dbb_shadow_lock) |
| 778 | break; |
| 779 | LCK_lock(tdbb, update_lock, LCK_SR, LCK_NO_WAIT); |
| 780 | } |
| 781 | |
| 782 | if (update_lock->lck_physical == LCK_SR) |
| 783 | LCK_release(tdbb, update_lock); |
| 784 | |
| 785 | return true; |
| 786 | } |
| 787 | } |
| 788 | else |
no test coverage detected