計数セマフォ (Counting Semaphore) / バイナリセマフォ
More...
#include <sync.hpp>
|
| | Semaphore (int32_t initial_count=1, int32_t max_count=1) |
| | セマフォを初期化します
|
| void | acquire () |
| | 資源を獲得するまで現在のタスクをブロックします
|
| bool | try_acquire () |
| | 資源の獲得を試みます (ノンブロッキング)
|
| void | release () |
| | 資源を返却し、待機中タスクがあれば最優先度のタスクを 1 つ起床させます
|
| int32_t | count () const |
計数セマフォ (Counting Semaphore) / バイナリセマフォ
資源の獲得・返却によるタスク間同期を行います。資源がない場合はタスクが State::Blocked に遷移して休止し、返却時に優先度の高いタスクから順に起床します。
sem.acquire();
sem.release();
計数セマフォ (Counting Semaphore) / バイナリセマフォ
Definition sync.hpp:24
◆ Semaphore()
| tk::Semaphore::Semaphore |
( |
int32_t | initial_count = 1, |
|
|
int32_t | max_count = 1 ) |
|
inlineexplicit |
セマフォを初期化します
- Parameters
-
| initial_count | 初期資源カウント (省略時: 1) |
| max_count | 最大資源カウント (省略時: 1) |
◆ acquire()
| void tk::Semaphore::acquire |
( |
| ) |
|
|
inline |
資源を獲得するまで現在のタスクをブロックします
資源カウントが 0 以下の場合はタスクが休止状態になり、CPU は他タスクへ譲渡されます (CPU消費ゼロ)。
◆ count()
| int32_t tk::Semaphore::count |
( |
| ) |
const |
|
inline |
◆ release()
| void tk::Semaphore::release |
( |
| ) |
|
|
inline |
資源を返却し、待機中タスクがあれば最優先度のタスクを 1 つ起床させます
◆ try_acquire()
| bool tk::Semaphore::try_acquire |
( |
| ) |
|
|
inline |
資源の獲得を試みます (ノンブロッキング)
- Returns
- true 獲得成功 (カウントが 1 減算された)
-
false 資源がないため獲得失敗 (ブロックせず即座に復帰)
The documentation for this class was generated from the following file:
- C:/Users/yoneda/Documents/Pico_Projects/tinykernel/tinykernel/include/tinykernel/sync.hpp