bthread: implement lock-free AtomicInteger128 for RISC-V (#3355)

* bthread: implement lock-free AtomicInteger128 for RISC-V

Replace mutex-based fallback with seqlock implementation for RISC-V
platform. This brings RISC-V in line with x86 (SSE) and ARM (NEON)
lock-free implementations.

Seqlock algorithm:
- Reader: read sequence, read data, verify sequence, retry if stale
- Writer: increment sequence, write data, increment sequence
- All memory accesses use fence instructions for ordering

Performance improvement:
- bthread_start_urgent latency: 1.5-2% reduction
- adding_func throughput: 25% improvement (541ns vs 722ns)

Signed-off-by: Xiaofei Gong <gongxiaofei24@iscas.ac.cn>
Signed-off-by: YuanSheng <yuansheng@isrc.iscas.ac.cn>

* fix: correct RISC-V inline assembly constraints for AtomicInteger128

- Use "m" (input) for ld instructions reading memory
- Use "=m" (output) for sd instructions writing memory
- Swap operand order in sd templates to match RISC-V syntax (register, memory)

The previous "+m" constraints in input operand positions caused compilation
errors on RISC-V. This fix ensures proper constraint usage:
- ld: memory is input "m", register is output "=r"
- sd: register is input "r", memory is output "=m"

Signed-off-by: Xiaofei Gong <gongxiaofei24@iscas.ac.cn>
Signed-off-by: YuanSheng <yuansheng@isrc.iscas.ac.cn>

---------

Signed-off-by: Xiaofei Gong <gongxiaofei24@iscas.ac.cn>
Signed-off-by: YuanSheng <yuansheng@isrc.iscas.ac.cn>
2 files changed
tree: af7c1f9cc4ff41ffad39bf83b10a3daa3b116ac7
  1. .github/
  2. bazel/
  3. cmake/
  4. community/
  5. docs/
  6. example/
  7. homebrew-formula/
  8. java/
  9. package/
  10. python/
  11. registry/
  12. src/
  13. test/
  14. tools/
  15. .asf.yaml
  16. .bazelignore
  17. .bazelrc
  18. .bazelversion
  19. .gitignore
  20. .licenserc.yaml
  21. AGENTS.md
  22. BUILD.bazel
  23. CHANGES.md
  24. CLAUDE.md
  25. CMakeLists.txt
  26. CODE_OF_CONDUCT.md
  27. config.h.in
  28. config_brpc.sh
  29. CONTRIBUTING.md
  30. Dockerfile
  31. LICENSE
  32. Makefile
  33. MODULE.bazel
  34. NOTICE
  35. README.md
  36. README_cn.md
  37. RELEASE_VERSION
  38. SECURITY.md
  39. THREAT_MODEL.md
  40. WORKSPACE
  41. WORKSPACE.bzlmod
README.md

中文版

Linux Build Status MacOs Build Status

brpc logo (light) brpc logo (dark)

bRPC is an Industrial-grade RPC framework using C++ Language, which is often used in high performance system such as Search, Storage, Machine learning, Advertisement, Recommendation etc.

“bRPC” means “better RPC”.

You can use it to:

Try it!

Contribute code

Please refer to here.

Feedback and Getting involved

Code of Conduct

We follow the code of conduct from Apache Software Foundation, please refer it here Link