Replace memory_order_consume with memory_order_acquire as in MPMC implementation

This commit is contained in:
Umar Farooq 2016-09-30 16:25:57 +02:00
parent 6742f969f8
commit d6a6b6e5dc
3 changed files with 7 additions and 7 deletions

View file

@ -103,7 +103,7 @@ int spsc_queue_pull_many(struct spsc_queue *q, void **ptrs[], size_t cnt)
int spsc_queue_available(struct spsc_queue *q)
{
if (atomic_load_explicit(&q->_tail, memory_order_consume) < atomic_load_explicit(&q->_head, memory_order_consume))
if (atomic_load_explicit(&q->_tail, memory_order_acquire) < atomic_load_explicit(&q->_head, memory_order_acquire))
return q->_head - q->_tail - 1;
else
return q->_head + (q->capacity - q->_tail);

View file

@ -58,7 +58,7 @@ int fibs[N];
int producer(void *ctx)
{
//printf("producer\n"); //DELETEME
printf("producer\n"); //DELETEME
struct spsc_queue *q = (struct spsc_queue *) ctx;
srand((unsigned) time(0) + thread_get_id());
@ -79,7 +79,7 @@ int producer(void *ctx)
void *fibptr = (void *) &fibs[count];
if (!spsc_queue_push(q, fibptr)) {
printf("Queue push failed at count %lu, %d\n", count, 1<<20);
printf("Queue push failed at count %lu, %d, free slots %d\n", count, 1<<20, spsc_queue_available(q));
return -1;
}
@ -91,7 +91,7 @@ int producer(void *ctx)
int consumer(void *ctx)
{
//printf("consumer\n"); //DELETEME
printf("consumer\n"); //DELETEME
struct spsc_queue *q = (struct spsc_queue *) ctx;
srand((unsigned) time(0) + thread_get_id());
@ -189,7 +189,7 @@ int test_multi_threaded(struct spsc_queue *q)
int main()
{
struct spsc_queue* q = NULL;
q = spsc_queue_init(q, 1<<20, &memtype_heap);
q = spsc_queue_init(q, 1<<24, &memtype_heap);
test_multi_threaded(q);
//test_single_threaded(q); /** Single threaded test fails with N > queue size*/

View file

@ -75,7 +75,7 @@ struct node* spsc_ub_alloc_node(struct spsc_ub_queue* q)
}
//q->_tailcopy = load_consume(q->_tail);
q->_tailcopy = atomic_load_explicit(&q->_tail, memory_order_consume);
q->_tailcopy = atomic_load_explicit(&q->_tail, memory_order_acquire);
if (q->_first != q->_tailcopy) {
struct node* n = q->_first;
@ -104,7 +104,7 @@ int spsc_ub_queue_push(struct spsc_ub_queue* q, void * v)
int spsc_ub_queue_pull(struct spsc_ub_queue* q, void** v)
{
if (atomic_load_explicit(&(q->_tail->_next), memory_order_consume)) {
if (atomic_load_explicit(&(q->_tail->_next), memory_order_acquire)) {
*v = q->_tail->_next->_value;
//store_release(&q->_tail, q->_tail->_next);