From bdd3915f83b93586d2250470ec8d8975fb8b0a97 Mon Sep 17 00:00:00 2001 From: Michael Shaw Date: Sat, 4 Jul 2026 22:19:40 +0200 Subject: [PATCH] atomic: add `atomic_xadd` Signed-off-by: Michael Shaw --- amd64/kernel/atomic.S | 5 +++++ include/kernel/atomic.h | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/amd64/kernel/atomic.S b/amd64/kernel/atomic.S index a434ea1..75d54e5 100644 --- a/amd64/kernel/atomic.S +++ b/amd64/kernel/atomic.S @@ -11,3 +11,8 @@ atomic_cmpxchg: mov eax, 1 ret +.global atomic_xadd +atomic_xadd: + mov rax, rsi + lock xadd [rdi], rax + ret diff --git a/include/kernel/atomic.h b/include/kernel/atomic.h index 79c29e5..cc77956 100644 --- a/include/kernel/atomic.h +++ b/include/kernel/atomic.h @@ -5,6 +5,6 @@ #include int atomic_cmpxchg(u32 *ptr, int a, int b); - +u64 atomic_xadd(u64 *ptr, u64 val); /* add val to *ptr and return old value of *ptr */ #endif /* _ATOMIC_H_ */