Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Paste
P229
atomic_* test, fails to link on i386
Active
Public
Actions
Authored by
mmokhi
on Oct 14 2018, 2:04 PM.
Edit Paste
Archive Paste
View Raw File
Subscribe
Mute Notifications
Award Token
Flag For Later
Tags
None
Subscribers
mmokhi
theraven
#include <stdint.h>
#include <stdatomic.h>
struct test {
volatile uint16_t a;
volatile uint64_t b;
volatile uint64_t c;
};
volatile struct test test = {
.a = 0,
.b = 0,
.c = 1
};
void compare_and_add(uint64_t dt, uint64_t argb) {
uint64_t oldb = test.b;
while(dt > oldb)
__atomic_compare_exchange(&test.b, &oldb, &dt, 1, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
__atomic_fetch_add(&test.b, 1, __ATOMIC_SEQ_CST);
__atomic_fetch_add(&test.b, dt, __ATOMIC_SEQ_CST);
__atomic_fetch_add(&test.b, argb, __ATOMIC_SEQ_CST);
}
void compare_and_add2(uint64_t dt, uint64_t argb) {
volatile struct test test2 = {0, 0, 1};
__atomic_fetch_add(&test2.b, 1, __ATOMIC_SEQ_CST);
__atomic_fetch_add(&test2.b, dt, __ATOMIC_SEQ_CST);
__atomic_fetch_add(&test2.b, argb, __ATOMIC_SEQ_CST);
}
int main (int argc, char **argv)
{
uint64_t ull1 = 1, ull2 = 0, ull3 = 2;
__atomic_load_n(&ull1, __ATOMIC_SEQ_CST);
__atomic_compare_exchange(&ull1, &ull2, &ull3, 1, __ATOMIC_SEQ_CST, __ATOMIC_SEQ_CST);
__atomic_fetch_add(&ull1, 1, __ATOMIC_SEQ_CST);
__atomic_fetch_sub(&test.b, 1, __ATOMIC_SEQ_CST);
__atomic_or_fetch(&ull1, ull2, __ATOMIC_SEQ_CST);
__atomic_and_fetch(&ull1, ull2, __ATOMIC_SEQ_CST);
return 0;
}
Event Timeline
mmokhi
created this paste.
Oct 14 2018, 2:04 PM
2018-10-14 14:04:07 (UTC+0)
mmokhi
created this object in space
S1 Global
.
Log In to Comment