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