• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Institute of Parallel And Distributed Systems (IPADS), Shanghai Jiao Tong University (SJTU)
3  * Licensed under the Mulan PSL v2.
4  * You can use this software according to the terms and conditions of the Mulan PSL v2.
5  * You may obtain a copy of Mulan PSL v2 at:
6  *     http://license.coscl.org.cn/MulanPSL2
7  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR
8  * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR
9  * PURPOSE.
10  * See the Mulan PSL v2 for more details.
11  */
12 
13 #ifndef CHCORE_DEBUG_LOCK
14 #define CHCORE_DEBUG_LOCK
15 
chcore_spin_lock(volatile int * lk)16 static inline void chcore_spin_lock(volatile int *lk)
17 {
18     for (;;) {
19         if (!__atomic_test_and_set(lk, __ATOMIC_ACQUIRE))
20             break;
21         while (*lk)
22             __asm__ __volatile__("nop" ::: "memory");
23 
24         // __asm__ __volatile__("wfe" ::: "memory");
25     }
26 }
27 
chcore_spin_unlock(volatile int * lk)28 static inline void chcore_spin_unlock(volatile int *lk)
29 {
30     __asm__ __volatile__("dmb ish" ::: "memory");
31     *lk = 0;
32 
33     // __asm__ __volatile__("sev" ::: "memory");
34 }
35 
36 #endif
37