wangzhengquan
2020-07-09 91f003aac4c95f4d2a2fc0782c9bea9d484b6919
queue/include/array_lock_free_queue.h
File was renamed from squeue/include/array_lock_free_queue.h
@@ -222,7 +222,9 @@
                currentWriteIndex, (currentWriteIndex + 1)));
    
    // Just made sure this index is reserved for this thread.
    m_theQueue[countToIndex(currentWriteIndex)] = a_data;
   // m_theQueue[countToIndex(currentWriteIndex)] = a_data;
    // printf("===sizeof(ELEM_T) = %d\n", sizeof(ELEM_T));
    memcpy((void *)(&m_theQueue[countToIndex(currentWriteIndex)]), (void *)(&a_data), sizeof(ELEM_T) );
    
    // update the maximum read index after saving the piece of data. It can't
    // fail if there is only one thread inserting in the queue. It might fail 
@@ -240,7 +242,7 @@
        // software threads than hardware processors and you have more
        // than 1 producer thread
        // have a look at sched_yield (POSIX.1b)
        //sched_yield();
        sched_yield();
    }
    // The value was successfully inserted into the queue
@@ -278,8 +280,8 @@
    #endif
        // retrieve the data from the queue
        a_data = m_theQueue[countToIndex(currentReadIndex)];
        //a_data = m_theQueue[countToIndex(currentReadIndex)];
        memcpy((void*) (&a_data), (void *)(&m_theQueue[countToIndex(currentReadIndex)]),sizeof(ELEM_T) );
        // try to perfrom now the CAS operation on the read index. If we succeed
        // a_data already contains what m_readIndex pointed to before we 
        // increased it