Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c32fcac

Browse files
committed
Add RISC-V spinlock support in s_lock.h.
Like the ARM case, just use gcc's __sync_lock_test_and_set(); that will compile into AMOSWAP.W.AQ which does what we need. At some point it might be worth doing some work on atomic ops for RISC-V, but this should be enough for a creditable port. Back-patch to all supported branches, just in case somebody wants to try them on RISC-V. Marek Szuba Discussion: https://postgr.es/m/[email protected]
1 parent 4279e5b commit c32fcac

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/include/storage/s_lock.h

+24
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,7 @@ tas(volatile slock_t *lock)
314314
#endif /* __INTEL_COMPILER */
315315
#endif /* __ia64__ || __ia64 */
316316

317+
317318
/*
318319
* On ARM and ARM64, we use __sync_lock_test_and_set(int *, int) if available.
319320
*
@@ -340,6 +341,29 @@ tas(volatile slock_t *lock)
340341
#endif /* __arm__ || __arm || __aarch64__ || __aarch64 */
341342

342343

344+
/*
345+
* RISC-V likewise uses __sync_lock_test_and_set(int *, int) if available.
346+
*/
347+
#if defined(__riscv)
348+
#ifdef HAVE_GCC__SYNC_INT32_TAS
349+
#define HAS_TEST_AND_SET
350+
351+
#define TAS(lock) tas(lock)
352+
353+
typedef int slock_t;
354+
355+
static __inline__ int
356+
tas(volatile slock_t *lock)
357+
{
358+
return __sync_lock_test_and_set(lock, 1);
359+
}
360+
361+
#define S_UNLOCK(lock) __sync_lock_release(lock)
362+
363+
#endif /* HAVE_GCC__SYNC_INT32_TAS */
364+
#endif /* __riscv */
365+
366+
343367
/* S/390 and S/390x Linux (32- and 64-bit zSeries) */
344368
#if defined(__s390__) || defined(__s390x__)
345369
#define HAS_TEST_AND_SET

0 commit comments

Comments
 (0)