Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // header
- extern struct report *_report;
- void report_copy(const void *ptr);
- // *.c
- struct report *_report = NULL;
- struct report _r1 = {0};
- struct report _r2 = {0};
- //TODO
- //__atomic_store(_report, &_r2, __ATOMIC_SEQ_CST);
- void report_copy(const void *ptr) {
- if (_report == NULL) {
- _report = &_r1;
- }
- if (_report == &_r1) {
- memcpy(&_r2, ptr, sizeof(struct report));
- __sync_val_compare_and_swap(&_report, &_r1, &_r2);
- } else if (_report == &_r2) {
- memcpy(&_r1, ptr, sizeof(struct report));
- __sync_val_compare_and_swap(&_report, &_r2, &_r1);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement