tk::Semaphore sync.hpp int32_t int32_t tk::Semaphore::count_ count_ tk::Semaphore::count_ int32_t int32_t tk::Semaphore::max_count_ max_count_ tk::Semaphore::max_count_ task_mask_t task_mask_t tk::Semaphore::wait_mask_ wait_mask_ tk::Semaphore::wait_mask_ {0} tk::Semaphore::Semaphore (int32_t initial_count=1, int32_t max_count=1) Semaphore tk::Semaphore::Semaphore int32_t initial_count 1 int32_t max_count 1 セマフォを初期化します initial_count 初期資源カウント (省略時: 1) max_count 最大資源カウント (省略時: 1) void void tk::Semaphore::acquire () acquire tk::Semaphore::acquire 資源を獲得するまで現在のタスクをブロックします 資源カウントが 0 以下の場合はタスクが休止状態になり、CPU は他タスクへ譲渡されます (CPU消費ゼロ)。 bool bool tk::Semaphore::try_acquire () try_acquire tk::Semaphore::try_acquire 資源の獲得を試みます (ノンブロッキング) true 獲得成功 (カウントが 1 減算された) false 資源がないため獲得失敗 (ブロックせず即座に復帰) void void tk::Semaphore::release () release tk::Semaphore::release 資源を返却し、待機中タスクがあれば最優先度のタスクを 1 つ起床させます int32_t int32_t tk::Semaphore::count () const count tk::Semaphore::count 現在の資源カウントを取得 計数セマフォ (Counting Semaphore) / バイナリセマフォ 資源の獲得・返却によるタスク間同期を行います。資源がない場合はタスクが State::Blocked に遷移して休止し、返却時に優先度の高いタスクから順に起床します。 tk::Semaphoresem(0,5);//初期値0、最大5 //タスク側(資源が空くまでブロック待機) sem.acquire(); //シグナル送信側(割り込みや他タスクから返却・通知) sem.release(); tk::Semaphoreacquire tk::Semaphorecount tk::Semaphorecount_ tk::Semaphoremax_count_ tk::Semaphorerelease tk::SemaphoreSemaphore tk::Semaphoretry_acquire tk::Semaphorewait_mask_