2
|
1 __code putSynchronizedQueue(struct SynchronizedQueue* queue, union Data* data, __code next(...)) {
|
|
2 Element* element = new Element();
|
|
3 element->data = data;
|
|
4 element->next = NULL;
|
|
5 Element* last = queue->last;
|
|
6 Element* nextElement = last->next;
|
|
7 if (last != queue->last) {
|
|
8 goto putSynchronizedQueue();
|
|
9 }
|
|
10 if (nextElement == NULL) {
|
|
11 struct Atomic* atomic = queue->atomic;
|
|
12 goto atomic->checkAndSet(&last->next, nextElement, element, next(...), putSynchronizedQueue);
|
|
13 } else { // wrong last element
|
|
14 struct Atomic* atomic = queue->atomic;
|
|
15 goto atomic->checkAndSet(&queue->last, last, nextElement, putSynchronizedQueue, putSynchronizedQueue);
|
|
16 }
|
|
17 }
|