13d0407baSopenharmony_ci/*
23d0407baSopenharmony_ci * Copyright 2021 Rockchip Electronics Co. LTD
33d0407baSopenharmony_ci *
43d0407baSopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
53d0407baSopenharmony_ci * you may not use this file except in compliance with the License.
63d0407baSopenharmony_ci * You may obtain a copy of the License at
73d0407baSopenharmony_ci *
83d0407baSopenharmony_ci *      http://www.apache.org/licenses/LICENSE-2.0
93d0407baSopenharmony_ci *
103d0407baSopenharmony_ci * Unless required by applicable law or agreed to in writing, software
113d0407baSopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
123d0407baSopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
133d0407baSopenharmony_ci * See the License for the specific language governing permissions and
143d0407baSopenharmony_ci * limitations under the License.
153d0407baSopenharmony_ci */
163d0407baSopenharmony_ci
173d0407baSopenharmony_ci#ifndef __MPP_LOCK_H__
183d0407baSopenharmony_ci#define __MPP_LOCK_H__
193d0407baSopenharmony_ci
203d0407baSopenharmony_ci#include <stdbool.h>
213d0407baSopenharmony_ci
223d0407baSopenharmony_ci#include "rk_type.h"
233d0407baSopenharmony_ci
243d0407baSopenharmony_ci#define MPP_FETCH_ADD           __sync_fetch_and_add
253d0407baSopenharmony_ci#define MPP_FETCH_SUB           __sync_fetch_and_sub
263d0407baSopenharmony_ci#define MPP_FETCH_OR            __sync_fetch_and_or
273d0407baSopenharmony_ci#define MPP_FETCH_AND           __sync_fetch_and_and
283d0407baSopenharmony_ci#define MPP_FETCH_XOR           __sync_fetch_and_xor
293d0407baSopenharmony_ci#define MPP_FETCH_NAND          __sync_fetch_and_nand
303d0407baSopenharmony_ci
313d0407baSopenharmony_ci#define MPP_ADD_FETCH           __sync_add_and_fetch
323d0407baSopenharmony_ci#define MPP_SUB_FETCH           __sync_sub_and_fetch
333d0407baSopenharmony_ci#define MPP_OR_FETCH            __sync_or_and_fetch
343d0407baSopenharmony_ci#define MPP_AND_FETCH           __sync_and_and_fetch
353d0407baSopenharmony_ci#define MPP_XOR_FETCH           __sync_xor_and_fetch
363d0407baSopenharmony_ci#define MPP_NAND_FETCH          __sync_nand_and_fetch
373d0407baSopenharmony_ci
383d0407baSopenharmony_ci#define MPP_BOOL_CAS            __sync_bool_compare_and_swap
393d0407baSopenharmony_ci#define MPP_VAL_CAS             __sync_val_compare_and_swap
403d0407baSopenharmony_ci
413d0407baSopenharmony_ci#define MPP_SYNC                __sync_synchronize
423d0407baSopenharmony_ci#define MPP_SYNC_TEST_SET       __sync_lock_test_and_set
433d0407baSopenharmony_ci#define MPP_SYNC_CLR            __sync_lock_release
443d0407baSopenharmony_ci
453d0407baSopenharmony_ci#ifdef __cplusplus
463d0407baSopenharmony_ciextern "C" {
473d0407baSopenharmony_ci#endif
483d0407baSopenharmony_ci
493d0407baSopenharmony_citypedef struct {
503d0407baSopenharmony_ci    RK_U32  lock;
513d0407baSopenharmony_ci} spinlock_t;
523d0407baSopenharmony_ci
533d0407baSopenharmony_civoid mpp_spinlock_init(spinlock_t *lock);
543d0407baSopenharmony_civoid mpp_spinlock_lock(spinlock_t *lock);
553d0407baSopenharmony_civoid mpp_spinlock_unlock(spinlock_t *lock);
563d0407baSopenharmony_cibool mpp_spinlock_trylock(spinlock_t *lock);
573d0407baSopenharmony_ci
583d0407baSopenharmony_ci#ifdef __cplusplus
593d0407baSopenharmony_ci}
603d0407baSopenharmony_ci#endif
613d0407baSopenharmony_ci
623d0407baSopenharmony_ci#endif /*__MPP_LOCK_H__*/
63