1 /** 2 * @file semaphore.h 3 * @author fslngjin (lonjin@RinGoTek.cn) 4 * @brief 信号量 5 * @version 0.1 6 * @date 2022-04-12 7 * 8 * @copyright Copyright (c) 2022 9 * 10 */ 11 12 #pragma once 13 #include <common/atomic.h> 14 15 #include <common/wait_queue.h> 16 17 /** 18 * @brief 信号量的结构体 19 * 20 */ 21 typedef struct 22 { 23 atomic_t counter; 24 wait_queue_node_t wait_queue; 25 } semaphore_t; 26 27 28 /** 29 * @brief 初始化信号量 30 * 31 * @param sema 信号量对象 32 * @param count 信号量的初始值 33 */ semaphore_init(semaphore_t * sema,ul count)34static __always_inline void semaphore_init(semaphore_t *sema, ul count) 35 { 36 atomic_set(&sema->counter, count); 37 wait_queue_init(&sema->wait_queue, NULL); 38 } 39 40 /** 41 * @brief 信号量down 42 * 43 * @param sema 44 */ 45 void semaphore_down(semaphore_t *sema); 46 47 void semaphore_up(semaphore_t *sema);