Note: The queue should not be accessed concurrently while it's being deleted. It's up to the user to synchronize this. This method is not thread safe.
| 793 | // being deleted. It's up to the user to synchronize this. |
| 794 | // This method is not thread safe. |
| 795 | ~ConcurrentQueue() { |
| 796 | // Destroy producers |
| 797 | auto ptr = producerListTail.load(std::memory_order_relaxed); |
| 798 | while (ptr != nullptr) { |
| 799 | auto next = ptr->next_prod(); |
| 800 | if (ptr->token != nullptr) { |
| 801 | ptr->token->producer = nullptr; |
| 802 | } |
| 803 | destroy(ptr); |
| 804 | ptr = next; |
| 805 | } |
| 806 | |
| 807 | // Destroy implicit producer hash tables |
| 808 | if (INITIAL_IMPLICIT_PRODUCER_HASH_SIZE != 0) { |
| 809 | auto hash = implicitProducerHash.load(std::memory_order_relaxed); |
| 810 | while (hash != nullptr) { |
| 811 | auto prev = hash->prev; |
| 812 | if (prev != |
| 813 | nullptr) { // The last hash is part of this object and was not allocated dynamically |
| 814 | for (size_t i = 0; i != hash->capacity; ++i) { |
| 815 | hash->entries[i].~ImplicitProducerKVP(); |
| 816 | } |
| 817 | hash->~ImplicitProducerHash(); |
| 818 | (Traits::free)(hash); |
| 819 | } |
| 820 | hash = prev; |
| 821 | } |
| 822 | } |
| 823 | |
| 824 | // Destroy global free list |
| 825 | auto block = freeList.head_unsafe(); |
| 826 | while (block != nullptr) { |
| 827 | auto next = block->freeListNext.load(std::memory_order_relaxed); |
| 828 | if (block->dynamicallyAllocated) { |
| 829 | destroy(block); |
| 830 | } |
| 831 | block = next; |
| 832 | } |
| 833 | |
| 834 | // Destroy initial free list |
| 835 | destroy_array(initialBlockPool, initialBlockPoolSize); |
| 836 | } |
| 837 | |
| 838 | // Disable copying and copy assignment |
| 839 | ConcurrentQueue(ConcurrentQueue const &) MOODYCAMEL_DELETE_FUNCTION; |
nothing calls this directly
no test coverage detected