---
title: Fetch_add
description: 原子加
url: "https://www.hikunpeng.com/document/detail/zh/kunpengdbs/ecosystemEnable/databasepg/kunpengdbsolution_12_0013.html"
---

# Fetch_add

原子加

- x86平台
  1 2 3 4 5 6 7 8 9 10 11 12 static inline uint64 pg_atomic_fetch_add_u64_impl(volatile pg_atomic_uint64 *ptr, int64 add_) { uint64 res; __asm__ __volatile__( " lock \n" " xaddq %0,%1 \n" : "=q"(res), "=m"(ptr->value) : "0" (add_), "m"(ptr->value) : "memory", "cc"); return res; }


- AArch64平台
  1 2 3 4 5 static inline uint64 pg_atomic_fetch_add_u64_impl(volatile pg_atomic_uint64 *ptr, int64 add_) { return __sync_fetch_and_add(&ptr->value, add_); }
