File was renamed from squeue/include/array_lock_free_queue.h |
| | |
| | | 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 |
| | |
| | | // 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 |
| | |
| | | #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 |