eec78d9f5d
* [utest/mm] add testcase for create/init format codes of create/init in components/mm * [libcpu/aarch64] fix user stack check routine * [kservice] export API for utest * [utest/mm] testcase for aspace_map format & modify the files under components/mm related with aspace_map * [lwp/user_mm] add user_map_varea for mmap feature * [mm] rename rt_mm_fault_try_fix to rt_aspace_fault_try_fix * [utest/mm] testcase for synchronization * [mm] modify unmap api to improve throughput * [utest/mm] testcases for cache and varea map * [format] remove extra space * [utest/mm] fix testcase problem in header * [lwp] extend map_user_varea with a flag * [utest/mm] testcase for lwp_map_user_varea * [libcpu/arm/cortex-a] fix kernel space layout * [utest/mm] adjust for armv7 arch
38 lines
760 B
C
38 lines
760 B
C
/*
|
|
* Copyright (c) 2006-2023, RT-Thread Development Team
|
|
*
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*
|
|
* Change Logs:
|
|
* Date Author Notes
|
|
* 2023-03-24 WangXiaoyao Complete testcase for synchronization
|
|
*/
|
|
#ifndef __SEMAPHORE_H__
|
|
#define __SEMAPHORE_H__
|
|
|
|
#include <stdatomic.h>
|
|
|
|
typedef struct {
|
|
atomic_int count;
|
|
} semaphore_t;
|
|
|
|
void semaphore_init(semaphore_t *sem, int count)
|
|
{
|
|
atomic_init(&sem->count, count);
|
|
}
|
|
|
|
void semaphore_wait(semaphore_t *sem)
|
|
{
|
|
int count;
|
|
do {
|
|
count = atomic_load(&sem->count);
|
|
} while (count == 0 || !atomic_compare_exchange_weak(&sem->count, &count, count - 1));
|
|
}
|
|
|
|
void semaphore_signal(semaphore_t *sem)
|
|
{
|
|
atomic_fetch_add(&sem->count, 1);
|
|
}
|
|
|
|
#endif /* __SEMAPHORE_H__ */
|