1 /* SPDX-License-Identifier: Apache-2.0 OR MIT */ 2 /* 3 * Copyright (c) 2021 Rockchip Electronics Co., Ltd. 4 */ 5 6 #ifndef __MPP_LOCK_H__ 7 #define __MPP_LOCK_H__ 8 9 #include <stdbool.h> 10 11 #include "rk_type.h" 12 13 #define MPP_FETCH_ADD __sync_fetch_and_add 14 #define MPP_FETCH_SUB __sync_fetch_and_sub 15 #define MPP_FETCH_OR __sync_fetch_and_or 16 #define MPP_FETCH_AND __sync_fetch_and_and 17 #define MPP_FETCH_XOR __sync_fetch_and_xor 18 #define MPP_FETCH_NAND __sync_fetch_and_nand 19 20 #define MPP_ADD_FETCH __sync_add_and_fetch 21 #define MPP_SUB_FETCH __sync_sub_and_fetch 22 #define MPP_OR_FETCH __sync_or_and_fetch 23 #define MPP_AND_FETCH __sync_and_and_fetch 24 #define MPP_XOR_FETCH __sync_xor_and_fetch 25 #define MPP_NAND_FETCH __sync_nand_and_fetch 26 27 #define MPP_BOOL_CAS __sync_bool_compare_and_swap 28 #define MPP_VAL_CAS __sync_val_compare_and_swap 29 30 #define MPP_SYNC __sync_synchronize 31 #define MPP_SYNC_TEST_SET __sync_lock_test_and_set 32 #define MPP_SYNC_CLR __sync_lock_release 33 34 #ifdef __cplusplus 35 extern "C" { 36 #endif 37 38 typedef struct { 39 RK_U32 lock; 40 RK_U32 debug; 41 RK_S64 count; 42 RK_S64 time; 43 } spinlock_t; 44 45 void mpp_spinlock_init(spinlock_t *lock); 46 void mpp_spinlock_deinit(spinlock_t *lock, const char *name); 47 void mpp_spinlock_lock(spinlock_t *lock); 48 void mpp_spinlock_unlock(spinlock_t *lock); 49 bool mpp_spinlock_trylock(spinlock_t *lock); 50 51 #ifdef __cplusplus 52 } 53 #endif 54 55 #endif /*__MPP_LOCK_H__*/ 56