1
0
mirror of https://github.com/rcore-os/rCore.git synced 2024-11-25 17:33:28 +04:00

Add impl of atomic_fetch_*

This commit is contained in:
WangRunji 2018-10-26 02:31:05 +08:00
parent 0680023e35
commit 95ab9caba1

View File

@ -46,4 +46,16 @@ char __atomic_compare_exchange_4(int* dst, int* expected, int desired) {
return sc_ret == 0;
}
return 0;
}
int __atomic_fetch_add_4(int* ptr, int val) {
int res;
__asm__ __volatile__("amoadd.w.rl %0, %1, (%2)" : "=r"(res) : "r"(val), "r"(ptr) : "memory");
return res;
}
int __atomic_fetch_sub_4(int* ptr, int val) {
int res;
__asm__ __volatile__("amoadd.w.rl %0, %1, (%2)" : "=r"(res) : "r"(-val), "r"(ptr) : "memory");
return res;
}