comparison src/parallel_execution/AtomicReference.cbc @ 444:0c024ea61601

Using cas interface but occurred warning
author Tatsuki IHA <innparusu@cr.ie.u-ryukyu.ac.jp>
date Sun, 26 Nov 2017 04:26:44 +0900
parents 5a737c3df91c
children 8d7e5d48cad3
comparison
equal deleted inserted replaced
443:ff2764cb5edb 444:0c024ea61601
1 #include "../context.h" 1 #include "../context.h"
2 2
3 #include <stdio.h> 3 #include <stdio.h>
4 4
5 /* 5 Atomic* createAtomicReference(struct Context* context) {
6 * Nonnon-blocking atomic of Paper: Simple, Fast, and Practical Non-Blocking and Blocking Concurrent Atomic Algorithms(https://www.research.ibm.com/people/m/michael/podc-1996.pdf).
7 */
8
9 Atomic* createAtomicReference(struct Context* context, union Data* data) {
10 struct Atomic* atomic = new Atomic(); 6 struct Atomic* atomic = new Atomic();
11 struct AtomicReference* atomicReference = new AtomicReference(); 7 struct AtomicReference* atomicReference = new AtomicReference();
12 atomicReference->data = data; 8 atomic->atomic = (union Data*)atomicReference;
13 atomic->atomic = AtomicReference;
14 atomic->checkAndSet = C_checkAndSetAtomicReference; 9 atomic->checkAndSet = C_checkAndSetAtomicReference;
15 return atomic; 10 return atomic;
16 } 11 }
17 12
18 __code checkAndSetAtomicReference(struct AtomicReference* atomic, union Data* data, __code next(...), __code fail(...)) { 13 __code checkAndSetAtomicReference(struct AtomicReference* atomic, union Data** ptr, union Data* oldData, union Data* newData, __code next(...), __code fail(...)) {
19 union Data* oldData = atomic->data; 14 if (__sync_bool_compare_and_swap(ptr, oldData, newData)) {
20 if (__sync_bool_compare_and_swap(&atomic->data, oldData, data)) {
21 goto next(...); 15 goto next(...);
22 } 16 }
23 goto fail(...); 17 goto fail(...);
24 } 18 }