DragonOS/kernel/common/semaphore.h

47 lines
771 B
C
Raw Normal View History

2022-04-12 13:30:07 +00:00
/**
* @file semaphore.h
* @author fslngjin (lonjin@RinGoTek.cn)
* @brief
* @version 0.1
* @date 2022-04-12
*
* @copyright Copyright (c) 2022
*
*/
#pragma once
#include <common/atomic.h>
2022-04-12 13:30:07 +00:00
2022-08-14 17:42:34 +00:00
#include <common/wait_queue.h>
2022-04-12 13:30:07 +00:00
/**
* @brief
*
*/
typedef struct
{
atomic_t counter;
wait_queue_node_t wait_queue;
} semaphore_t;
2022-08-14 17:42:34 +00:00
2022-04-12 13:30:07 +00:00
/**
* @brief
*
* @param sema
* @param count
*/
2022-08-14 17:42:34 +00:00
static __always_inline void semaphore_init(semaphore_t *sema, ul count)
2022-04-12 13:30:07 +00:00
{
atomic_set(&sema->counter, count);
wait_queue_init(&sema->wait_queue, NULL);
}
/**
* @brief down
*
* @param sema
*/
2022-08-14 17:42:34 +00:00
void semaphore_down(semaphore_t *sema);
2022-04-12 13:30:07 +00:00
2022-08-14 17:42:34 +00:00
void semaphore_up(semaphore_t *sema);