ck_fifo: MPMC variant will return "garbage" pointer which user can re-use.

ck_pring
Samy Al Bahra 14 years ago
parent 158e1580f5
commit 7bd5259505

@ -155,8 +155,6 @@ struct ck_fifo_mpmc {
struct ck_fifo_mpmc_pointer head;
char pad[CK_MD_CACHELINE - sizeof(struct ck_fifo_mpmc_pointer)];
struct ck_fifo_mpmc_pointer tail;
struct ck_fifo_mpmc_entry *head_snapshot;
struct ck_fifo_mpmc_pointer garbage;
};
typedef struct ck_fifo_mpmc ck_fifo_mpmc_t;
@ -170,8 +168,6 @@ ck_fifo_mpmc_init(struct ck_fifo_mpmc *fifo, struct ck_fifo_mpmc_entry *stub)
ck_pr_store_ptr(&fifo->tail.generation, 0);
ck_pr_store_ptr(&stub->next.pointer, NULL);
ck_pr_store_ptr(&stub->next.generation, 0);
ck_pr_store_ptr(&fifo->head_snapshot, stub);
ck_pr_store_ptr(&fifo->garbage, stub);
return;
}
@ -233,7 +229,7 @@ ck_fifo_mpmc_enqueue(struct ck_fifo_mpmc *fifo, struct ck_fifo_mpmc_entry *entry
}
CK_CC_INLINE static bool
ck_fifo_mpmc_dequeue(struct ck_fifo_mpmc *fifo, void *value)
ck_fifo_mpmc_dequeue(struct ck_fifo_mpmc *fifo, void *value, ck_fifo_mpmc_entry_t **garbage)
{
struct ck_fifo_mpmc_pointer head, tail, next, update;
ck_backoff_t backoff = CK_BACKOFF_INITIALIZER;
@ -274,6 +270,7 @@ ck_fifo_mpmc_dequeue(struct ck_fifo_mpmc *fifo, void *value)
}
}
*garbage = head.pointer;
return (true);
}

@ -59,6 +59,7 @@ main(void)
ck_fifo_mpmc_t mpmc_fifo;
ck_fifo_mpmc_entry_t mpmc_entry[ENTRIES];
ck_fifo_mpmc_entry_t mpmc_stub;
ck_fifo_mpmc_entry_t *garbage;
#endif
#ifdef CK_F_FIFO_SPSC
@ -145,7 +146,7 @@ main(void)
s = rdtsc();
for (j = 0; j < ENTRIES; j++)
ck_fifo_mpmc_dequeue(&mpmc_fifo, &r);
ck_fifo_mpmc_dequeue(&mpmc_fifo, &r, &garbage);
e = rdtsc();
a += e - s;
}

@ -64,7 +64,7 @@ test(void *c)
#ifdef CK_F_FIFO_MPMC
struct context *context = c;
struct entry *entry;
ck_fifo_mpmc_entry_t *fifo_entry;
ck_fifo_mpmc_entry_t *fifo_entry, *garbage;
int i, j;
if (aff_iterate(&a)) {
@ -81,7 +81,7 @@ test(void *c)
entry = malloc(sizeof(struct entry));
entry->tid = context->tid;
ck_fifo_mpmc_enqueue(&fifo, fifo_entry, entry);
if (ck_fifo_mpmc_dequeue(&fifo, &entry) == false) {
if (ck_fifo_mpmc_dequeue(&fifo, &entry, &garbage) == false) {
fprintf(stderr, "ERROR [%u] Queue should never be empty.\n", context->tid);
exit(EXIT_FAILURE);
}

Loading…
Cancel
Save