From 91f003aac4c95f4d2a2fc0782c9bea9d484b6919 Mon Sep 17 00:00:00 2001 From: wangzhengquan <wangzhengquan85@126.com> Date: 星期四, 09 七月 2020 14:48:07 +0800 Subject: [PATCH] update --- queue/include/array_lock_free_queue.h | 10 ++++++---- 1 files changed, 6 insertions(+), 4 deletions(-) diff --git a/squeue/include/array_lock_free_queue.h b/queue/include/array_lock_free_queue.h similarity index 95% rename from squeue/include/array_lock_free_queue.h rename to queue/include/array_lock_free_queue.h index e03d6cd..931e839 100644 --- a/squeue/include/array_lock_free_queue.h +++ b/queue/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 -- Gitblit v1.8.0