classtk_1_1_semaphore.tex 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. \doxysection{tk::Semaphore クラス}
  2. \label{classtk_1_1_semaphore}\index{tk::Semaphore@{tk::Semaphore}}
  3. 計数セマフォ (Counting \doxyref{Semaphore}{p.}{classtk_1_1_semaphore}) / バイナリセマフォ
  4. {\ttfamily \+\#include $<$sync.\+hpp$>$}
  5. \doxysubsubsection*{公開メンバ関数}
  6. \begin{DoxyCompactItemize}
  7. \item
  8. \textbf{ Semaphore} (int32\+\_\+t initial\+\_\+count=1, int32\+\_\+t max\+\_\+count=1)
  9. \begin{DoxyCompactList}\small\item\em セマフォを初期化します \end{DoxyCompactList}\item
  10. void \textbf{ acquire} ()
  11. \begin{DoxyCompactList}\small\item\em 資源を獲得するまで現在のタスクをブロックします \end{DoxyCompactList}\item
  12. bool \textbf{ try\+\_\+acquire} ()
  13. \begin{DoxyCompactList}\small\item\em 資源の獲得を試みます (ノンブロッキング) \end{DoxyCompactList}\item
  14. void \textbf{ release} ()
  15. \begin{DoxyCompactList}\small\item\em 資源を返却し、待機中タスクがあれば最優先度のタスクを 1 つ起床させます \end{DoxyCompactList}\item
  16. int32\+\_\+t \textbf{ count} () const
  17. \end{DoxyCompactItemize}
  18. \doxysubsection{詳解}
  19. 計数セマフォ (Counting \doxyref{Semaphore}{p.}{classtk_1_1_semaphore}) / バイナリセマフォ
  20. 資源の獲得・返却によるタスク間同期を行います。資源がない場合はタスクが {\ttfamily State::\+\+Blocked} に遷移して休止し、返却時に優先度の高いタスクから順に起床します。
  21. \begin{DoxyCode}{0}
  22. \DoxyCodeLine{tk::Semaphore\ sem(0,\ 5);\ \textcolor{comment}{//\ 初期値0、最大5}}
  23. \DoxyCodeLine{}
  24. \DoxyCodeLine{\textcolor{comment}{//\ タスク側\ (資源が空くまでブロック待機)}}
  25. \DoxyCodeLine{sem.acquire();}
  26. \DoxyCodeLine{}
  27. \DoxyCodeLine{\textcolor{comment}{//\ シグナル送信側\ (割り込みや他タスクから返却・通知)}}
  28. \DoxyCodeLine{sem.release();}
  29. \end{DoxyCode}
  30. \label{classtk_1_1_semaphore_doc-constructors}
  31. \doxysubsection{構築子と解体子}
  32. \index{tk::Semaphore@{tk::Semaphore}!Semaphore@{Semaphore}}
  33. \index{Semaphore@{Semaphore}!tk::Semaphore@{tk::Semaphore}}
  34. \doxysubsubsection{Semaphore()}
  35. {\footnotesize\ttfamily \label{classtk_1_1_semaphore_a66c5ac90338a6fcc6a9c2f22f1586de8}
  36. tk::\+\+Semaphore::\+\+Semaphore (\begin{DoxyParamCaption}\item[{int32\+\_\+t}]{initial\+\_\+count}{ = {\ttfamily 1}, }\item[{int32\+\_\+t}]{max\+\_\+count}{ = {\ttfamily 1}}\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}, {\ttfamily [explicit]}}
  37. セマフォを初期化します
  38. \begin{DoxyParams}{引数}
  39. {\em initial\+\_\+count} & 初期資源カウント (省略時: 1) \\
  40. \hline
  41. {\em max\+\_\+count} & 最大資源カウント (省略時: 1) \\
  42. \hline
  43. \end{DoxyParams}
  44. \label{classtk_1_1_semaphore_doc-func-members}
  45. \doxysubsection{関数詳解}
  46. \index{tk::Semaphore@{tk::Semaphore}!acquire@{acquire}}
  47. \index{acquire@{acquire}!tk::Semaphore@{tk::Semaphore}}
  48. \doxysubsubsection{acquire()}
  49. {\footnotesize\ttfamily \label{classtk_1_1_semaphore_a863ccee07bc701a78342c14503955d73}
  50. void tk::\+\+Semaphore::\+acquire (\begin{DoxyParamCaption}{}{}\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}
  51. 資源を獲得するまで現在のタスクをブロックします
  52. 資源カウントが 0 以下の場合はタスクが休止状態になり、\+CPU は他タスクへ譲渡されます (CPU消費ゼロ)。 \index{tk::Semaphore@{tk::Semaphore}!count@{count}}
  53. \index{count@{count}!tk::Semaphore@{tk::Semaphore}}
  54. \doxysubsubsection{count()}
  55. {\footnotesize\ttfamily \label{classtk_1_1_semaphore_ae53b9c57cc25fafb242a21776f112701}
  56. int32\+\_\+t tk::\+\+Semaphore::\+count (\begin{DoxyParamCaption}{}{}\end{DoxyParamCaption}) const\hspace{0.3cm}{\ttfamily [inline]}}
  57. 現在の資源カウントを取得 \index{tk::Semaphore@{tk::Semaphore}!release@{release}}
  58. \index{release@{release}!tk::Semaphore@{tk::Semaphore}}
  59. \doxysubsubsection{release()}
  60. {\footnotesize\ttfamily \label{classtk_1_1_semaphore_a7bb8eb8b0bd69b2f6b0a4d89d0f5b07b}
  61. void tk::\+\+Semaphore::\+release (\begin{DoxyParamCaption}{}{}\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}
  62. 資源を返却し、待機中タスクがあれば最優先度のタスクを 1 つ起床させます
  63. \index{tk::Semaphore@{tk::Semaphore}!try\_acquire@{try\_acquire}}
  64. \index{try\_acquire@{try\_acquire}!tk::Semaphore@{tk::Semaphore}}
  65. \doxysubsubsection{try\_acquire()}
  66. {\footnotesize\ttfamily \label{classtk_1_1_semaphore_a3a246c8afc866dc438186d0a53cad5c2}
  67. bool tk::\+\+Semaphore::\+try\+\_\+acquire (\begin{DoxyParamCaption}{}{}\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}
  68. 資源の獲得を試みます (ノンブロッキング)
  69. \begin{DoxyReturn}{戻り値}
  70. true 獲得成功 (カウントが 1 減算された)
  71. false 資源がないため獲得失敗 (ブロックせず即座に復帰)
  72. \end{DoxyReturn}
  73. このクラス詳解は次のファイルから抽出されました:\begin{DoxyCompactItemize}
  74. \item
  75. C:\+/\+\+Users/\+yoneda/\+\+Documents/\+\+Pico\+\_\+\+Projects/\+tinykernel/\+tinykernel/\+include/\+tinykernel/\textbf{ sync.\+hpp}\end{DoxyCompactItemize}