1 /* 2 * Copyright 2021 Rockchip Electronics Co. LTD 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef __MPP_LOCK_H__ 18 #define __MPP_LOCK_H__ 19 20 #include <stdbool.h> 21 22 #include "rk_type.h" 23 24 #define MPP_FETCH_ADD __sync_fetch_and_add 25 #define MPP_FETCH_SUB __sync_fetch_and_sub 26 #define MPP_FETCH_OR __sync_fetch_and_or 27 #define MPP_FETCH_AND __sync_fetch_and_and 28 #define MPP_FETCH_XOR __sync_fetch_and_xor 29 #define MPP_FETCH_NAND __sync_fetch_and_nand 30 31 #define MPP_ADD_FETCH __sync_add_and_fetch 32 #define MPP_SUB_FETCH __sync_sub_and_fetch 33 #define MPP_OR_FETCH __sync_or_and_fetch 34 #define MPP_AND_FETCH __sync_and_and_fetch 35 #define MPP_XOR_FETCH __sync_xor_and_fetch 36 #define MPP_NAND_FETCH __sync_nand_and_fetch 37 38 #define MPP_BOOL_CAS __sync_bool_compare_and_swap 39 #define MPP_VAL_CAS __sync_val_compare_and_swap 40 41 #define MPP_SYNC __sync_synchronize 42 #define MPP_SYNC_TEST_SET __sync_lock_test_and_set 43 #define MPP_SYNC_CLR __sync_lock_release 44 45 #ifdef __cplusplus 46 extern "C" { 47 #endif 48 49 typedef struct { 50 RK_U32 lock; 51 } spinlock_t; 52 53 void mpp_spinlock_init(spinlock_t *lock); 54 void mpp_spinlock_lock(spinlock_t *lock); 55 void mpp_spinlock_unlock(spinlock_t *lock); 56 bool mpp_spinlock_trylock(spinlock_t *lock); 57 58 #ifdef __cplusplus 59 } 60 #endif 61 62 #endif /*__MPP_LOCK_H__*/ 63