// File: bhhbazinga[P]LockFreeHashTable/./HazardPointer/reclaimer.h
// Function: Reclaimer::~Reclaimer()
Reclaimer::~Reclaimer() {
  // The Reclaimer destruct when the thread exit

  // 1.Hand over the hazard pointer
  for (int i = 0; i < hp_list_.size(); ++i) {
    // If assert fired, you should make sure no pointer is marked as hazard
    // before thread exit
    assert(nullptr == hp_list_[i]->ptr.load(std::memory_order_relaxed));
    hp_list_[i]->flag.clear();
  }

  // 2.Make sure reclaim all no hazard pointers
  for (auto it = reclaim_map_.begin(); it != reclaim_map_.end();) {
    // Wait until pointer is no hazard
    while (Hazard(it->first)) {
      std::this_thread::yield();
    }

    ReclaimNode* node = it->second;
    node->delete_func(node->ptr);
    delete node;
    it = reclaim_map_.erase(it);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x50(%rbp)
leaq 0x1772a(%rip), %rcx     # 0x19bf8
addq $0x10, %rcx
movq %rcx, (%rax)
movl $0x0, -0x1c(%rbp)
movq -0x50(%rbp), %rdi
movslq -0x1c(%rbp), %rax
movq %rax, -0x58(%rbp)
addq $0x8, %rdi
callq 0x3e80
movq %rax, %rcx
movq -0x58(%rbp), %rax
cmpq %rcx, %rax
jae 0x25d5
movq -0x50(%rbp), %rdi
addq $0x8, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x3ea0
movq (%rax), %rdi
addq $0x8, %rdi
xorl %esi, %esi
callq 0x3ec0
movq %rax, %rcx
xorl %eax, %eax
cmpq %rcx, %rax
jne 0x252c
jmp 0x254b
leaq 0xec29(%rip), %rdi      # 0x1115c
leaq 0xec5e(%rip), %rsi      # 0x11198
movl $0x9b, %edx
leaq 0xec6e(%rip), %rcx      # 0x111b4
callq 0x20c0
movq -0x50(%rbp), %rdi
addq $0x8, %rdi
movslq -0x1c(%rbp), %rsi
callq 0x3ea0
movq (%rax), %rax
movq %rax, -0x8(%rbp)
movl $0x5, -0xc(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
movl -0xc(%rbp), %edi
movl $0xffff, %esi           # imm = 0xFFFF
callq 0x5730
movl %eax, -0x5c(%rbp)
jmp 0x2584
movl -0x5c(%rbp), %eax
movl %eax, -0x10(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x6c(%rbp)
subl $0x3, %eax
je 0x25aa
jmp 0x2597
movl -0x6c(%rbp), %eax
subl $0x5, %eax
je 0x25b3
jmp 0x25a1
movq -0x68(%rbp), %rax
movb $0x0, (%rax)
jmp 0x25c5
movq -0x68(%rbp), %rax
movb $0x0, (%rax)
jmp 0x25c5
movq -0x68(%rbp), %rcx
xorl %eax, %eax
xchgb %al, (%rcx)
jmp 0x25c5
movq %rax, %rdi
callq 0x4000
jmp 0x25c7
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x24dc
movq -0x50(%rbp), %rdi
addq $0x20, %rdi
callq 0x3f40
movq %rax, -0x28(%rbp)
movq -0x50(%rbp), %rdi
addq $0x20, %rdi
callq 0x3fa0
movq %rax, -0x30(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x3f70
testb $0x1, %al
jne 0x260d
jmp 0x26b8
jmp 0x260f
leaq -0x28(%rbp), %rdi
callq 0x3fd0
movq -0x50(%rbp), %rdi
movq (%rax), %rsi
callq 0x26f0
movb %al, -0x6d(%rbp)
jmp 0x2629
movb -0x6d(%rbp), %al
testb $0x1, %al
jne 0x2632
jmp 0x2639
callq 0x4010
jmp 0x260f
leaq -0x28(%rbp), %rdi
callq 0x3fd0
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
movq %rax, %rdi
addq $0x10, %rdi
movq (%rax), %rsi
callq 0x4030
jmp 0x265f
movq -0x38(%rbp), %rax
movq %rax, -0x78(%rbp)
cmpq $0x0, %rax
je 0x2684
movq -0x78(%rbp), %rdi
callq 0x4070
movq -0x78(%rbp), %rdi
movl $0x30, %esi
callq 0x2150
movq -0x50(%rbp), %rdi
addq $0x20, %rdi
movq -0x28(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rsi
callq 0x4090
movq %rax, -0x80(%rbp)
jmp 0x26a3
movq -0x80(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x28(%rbp)
jmp 0x25e6
movq -0x50(%rbp), %rdi
addq $0x58, %rdi
callq 0x40d0
movq -0x50(%rbp), %rdi
addq $0x20, %rdi
callq 0x4130
movq -0x50(%rbp), %rdi
addq $0x8, %rdi
callq 0x4150
addq $0x80, %rsp
popq %rbp
retq
movq %rax, %rdi
callq 0x4000