Skip to content

Commit 55eac37

Browse files
committed
Avoid unlimited recursion in hazard GC
1 parent 90a5d0e commit 55eac37

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/jrd/HazardPtr.h

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,9 @@ namespace Jrd {
274274

275275

276276
// Shared read here means that any thread can read from vector using HP.
277-
// It can be modified only in single thread, caller is responsible for that.
277+
// It can be modified only in single thread, caller must take care modifying thread is single.
278278

279-
template <typename T, FB_SIZE_T CAP>
279+
template <typename T, FB_SIZE_T CAP, bool GC_ENABLED = true>
280280
class SharedReadVector : public Firebird::PermanentStorage
281281
{
282282
public:
@@ -384,7 +384,9 @@ namespace Jrd {
384384

385385
public:
386386
enum class GarbageCollectMethod {GC_NORMAL, GC_ALL, GC_FORCE};
387-
typedef SharedReadVector<const void*,INITIAL_SIZE>::Generation HazardPointers;
387+
// In this and only this case disable GC in delayedDelete()
388+
typedef SharedReadVector<const void*, INITIAL_SIZE, true> HazardPointersStorage;
389+
typedef HazardPointersStorage::Generation HazardPointers;
388390

389391
HazardDelayedDelete(MemoryPool& dbbPool, MemoryPool& attPool)
390392
: Firebird::PermanentStorage(dbbPool),
@@ -406,7 +408,7 @@ namespace Jrd {
406408
static void copyHazardPointers(thread_db* tdbb, LocalHP& local, Attachment* from);
407409

408410
Firebird::HalfStaticArray<HazardObject*, DELETED_LIST_SIZE> toDelete;
409-
SharedReadVector<const void*,INITIAL_SIZE> hazardPointers;
411+
HazardPointersStorage hazardPointers;
410412
};
411413

412414

@@ -424,8 +426,8 @@ namespace Jrd {
424426
hazardDelayed->remove(hazardPointer);
425427
}
426428

427-
template <typename T, FB_SIZE_T CAP>
428-
inline void SharedReadVector<T, CAP>::grow(HazardDelayedDelete* dd, FB_SIZE_T newSize)
429+
template <typename T, FB_SIZE_T CAP, bool GC_ENABLED>
430+
inline void SharedReadVector<T, CAP, GC_ENABLED>::grow(HazardDelayedDelete* dd, FB_SIZE_T newSize)
429431
{
430432
Generation* oldGeneration = writeAccessor();
431433
if (newSize && (oldGeneration->getCapacity() >= newSize))
@@ -440,7 +442,7 @@ namespace Jrd {
440442
v.store(newGeneration, std::memory_order_release);
441443

442444
// delay delete - someone else may access it
443-
dd->delayedDelete(oldGeneration);
445+
dd->delayedDelete(oldGeneration, GC_ENABLED);
444446
}
445447

446448

0 commit comments

Comments
 (0)