Skip to content

Commit 26b0853

Browse files
refine: improve RISC-V support with cpu_relax and const correctness
- Add RISC-V cpu_relax() implementation using fence.i instruction - Fix const correctness in AtomicInteger128 mutex operations Co-authored-by: gong-flying <gongxiaofei24@iscas.ac.cn>
1 parent f86d04e commit 26b0853

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

src/bthread/processor.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
# ifndef cpu_relax
2929
#if defined(ARCH_CPU_ARM_FAMILY)
3030
# define cpu_relax() asm volatile("yield\n": : :"memory")
31+
#elif defined(ARCH_CPU_RISCV_FAMILY)
32+
# define cpu_relax() asm volatile("fence.i\n": : :"memory")
3133
#elif defined(ARCH_CPU_LOONGARCH64_FAMILY)
3234
# define cpu_relax() asm volatile("nop\n": : :"memory");
3335
#else

src/bthread/task_group.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ AtomicInteger128::Value AtomicInteger128::load() const {
101101
return {value[0], value[1]};
102102
#else // __x86_64__ || __ARM_NEON
103103
// RISC-V and other architectures use mutex fallback
104-
BAIDU_SCOPED_LOCK(_mutex);
104+
BAIDU_SCOPED_LOCK(const_cast<FastPthreadMutex&>(_mutex));
105105
return _value;
106106
#endif // __x86_64__ || __ARM_NEON
107107
}
@@ -115,7 +115,7 @@ void AtomicInteger128::store(Value value) {
115115
vst1q_s64(reinterpret_cast<int64_t*>(&_value), v);
116116
#else
117117
// RISC-V and other architectures use mutex fallback
118-
BAIDU_SCOPED_LOCK(_mutex);
118+
BAIDU_SCOPED_LOCK(const_cast<FastPthreadMutex&>(_mutex));
119119
_value = value;
120120
#endif // __x86_64__ || __ARM_NEON
121121
}

0 commit comments

Comments
 (0)