33 QReadLocker lock(&m_migrationLock);
34 qint32 currentIndex = m_offset + index;
36 if (currentIndex < 0 || currentIndex >= m_capacity) {
40 currentIndex = m_offset + index;
44 bool needsUpdateExtent =
false;
49 int oldValue = m_buffer[currentIndex].loadAcquire();
54 if ((oldValue = m_buffer[currentIndex].loadAcquire()) == 0) {
56 if (m_min > index) m_min = index;
57 if (m_max < index) m_max = index;
60 needsUpdateExtent =
true;
62 m_buffer[currentIndex].storeRelease(1);
64 m_buffer[currentIndex].storeRelease(oldValue + 1);
68 }
else if (m_buffer[currentIndex].testAndSetOrdered(oldValue, oldValue + 1)) {
73 return needsUpdateExtent;
78 QReadLocker lock(&m_migrationLock);
79 qint32 currentIndex = m_offset + index;
81 bool needsUpdateExtent =
false;
84 const int oldValue = m_buffer[currentIndex].fetchAndAddAcquire(-1);
94 m_buffer[currentIndex].storeRelaxed(0);
102 if (m_min == index) updateMin();
103 if (m_max == index) updateMax();
106 needsUpdateExtent =
true;
109 return needsUpdateExtent;
161 qint32 currentIndex = m_offset + index;
163 if (currentIndex < 0 || currentIndex >= m_capacity) {
164 unsafeMigrate(index);
165 currentIndex = m_offset + index;
168 if (!m_buffer[currentIndex].fetchAndAddRelaxed(1)) {
169 if (m_min > index) m_min = index;
170 if (m_max < index) m_max = index;
177 qint32 oldCapacity = m_capacity;
178 qint32 oldOffset = m_offset;
179 qint32 currentIndex = m_offset + index;
181 while (currentIndex < 0 || currentIndex >= m_capacity) {
184 if (currentIndex < 0) {
186 currentIndex = m_offset + index;
190 if (m_capacity != oldCapacity) {
191 QAtomicInt *newBuffer =
new QAtomicInt[m_capacity];
192 qint32 start = m_offset - oldOffset;
194 for (qint32 i = 0; i < oldCapacity; ++i) {
195 newBuffer[start + i].storeRelaxed(m_buffer[i].loadRelaxed());
199 m_buffer = newBuffer;