view paper/src/putSynchronizedQueue.cbc @ 19:046b2b20d6c7 default tip

fix
author ryokka
date Mon, 09 Mar 2020 11:25:49 +0900
parents c7acb9211784
children
line wrap: on
line source

__code putSynchronizedQueue(struct SynchronizedQueue* queue, union Data* data, __code next(...)) {
    Element* element = new Element();
    element->data = data;
    element->next = NULL;
    Element* last = queue->last;
    Element* nextElement = last->next;
    if (last != queue->last) {
        goto putSynchronizedQueue();
    }
    if (nextElement == NULL) {
        struct Atomic* atomic = queue->atomic;
        goto atomic->checkAndSet(&last->next, nextElement, element, next(...), putSynchronizedQueue);
    } else { // wrong last element
        struct Atomic* atomic = queue->atomic;
        goto atomic->checkAndSet(&queue->last, last, nextElement, putSynchronizedQueue, putSynchronizedQueue);
    }
}