| | |
| | | } |
| | | |
| | | #ifdef _WITH_LOCK_FREE_Q_KEEP_REAL_SIZE |
| | | AtomicAdd(&m_count, 1); |
| | | if (m_count < Q_SIZE) { |
| | | AtomicAdd(&m_count, 1); |
| | | } |
| | | #endif |
| | | return true; |
| | | } |
| | |
| | | if (CAS(&m_readIndex, currentReadIndex, (currentReadIndex + 1))) { |
| | | #ifdef _WITH_LOCK_FREE_Q_KEEP_REAL_SIZE |
| | | // m_count.fetch_sub(1); |
| | | AtomicSub(&m_count, 1); |
| | | if (m_count > 0) { |
| | | AtomicSub(&m_count, 1); |
| | | } |
| | | #endif |
| | | return true; |
| | | } |
| | |
| | | |
| | | template<typename ELEM_T, typename Allocator> |
| | | ELEM_T &ArrayLockFreeQueue<ELEM_T, Allocator>::operator[](unsigned int i) { |
| | | #ifdef _WITH_LOCK_FREE_Q_KEEP_REAL_SIZE |
| | | int currentCount = m_count; |
| | | uint32_t currentReadIndex = m_readIndex; |
| | | if (i >= currentCount) { |
| | |
| | | << " is out of range\n"; |
| | | std::exit(EXIT_FAILURE); |
| | | } |
| | | #else |
| | | uint32_t currentReadIndex = m_readIndex; |
| | | #endif |
| | | return m_theQueue[countToIndex(currentReadIndex + i)]; |
| | | } |
| | | |