classtk_1_1_semaphore.tex 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. \doxysection{tk::Semaphore Class Reference}
  2. \hypertarget{classtk_1_1_semaphore}{}\label{classtk_1_1_semaphore}\index{tk::Semaphore@{tk::Semaphore}}
  3. 計数セマフォ (Counting \doxylink{classtk_1_1_semaphore}{Semaphore}) / バイナリセマフォ
  4. {\ttfamily \+\#include $<$sync.\+hpp$>$}
  5. \doxysubsubsection*{Public Member Functions}
  6. \begin{DoxyCompactItemize}
  7. \item
  8. \doxymbox{\hyperlink{classtk_1_1_semaphore_a66c5ac90338a6fcc6a9c2f22f1586de8}{Semaphore}} (int32\+\_\+t initial\+\_\+count=1, int32\+\_\+t max\+\_\+count=1)
  9. \begin{DoxyCompactList}\small\item\em セマフォを初期化します \end{DoxyCompactList}\item
  10. void \doxymbox{\hyperlink{classtk_1_1_semaphore_a863ccee07bc701a78342c14503955d73}{acquire}} ()
  11. \begin{DoxyCompactList}\small\item\em 資源を獲得するまで現在のタスクをブロックします \end{DoxyCompactList}\item
  12. bool \doxymbox{\hyperlink{classtk_1_1_semaphore_a3a246c8afc866dc438186d0a53cad5c2}{try\+\_\+acquire}} ()
  13. \begin{DoxyCompactList}\small\item\em 資源の獲得を試みます (ノンブロッキング) \end{DoxyCompactList}\item
  14. void \doxymbox{\hyperlink{classtk_1_1_semaphore_a7bb8eb8b0bd69b2f6b0a4d89d0f5b07b}{release}} ()
  15. \begin{DoxyCompactList}\small\item\em 資源を返却し、待機中タスクがあれば最優先度のタスクを 1 つ起床させます \end{DoxyCompactList}\item
  16. int32\+\_\+t \doxymbox{\hyperlink{classtk_1_1_semaphore_ae53b9c57cc25fafb242a21776f112701}{count}} () const
  17. \end{DoxyCompactItemize}
  18. \doxysubsection{Detailed Description}
  19. 計数セマフォ (Counting \doxylink{classtk_1_1_semaphore}{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. \Hypertarget{classtk_1_1_semaphore_doc-constructors}
  32. \doxysubsection{Constructor \& Destructor Documentation}
  33. \Hypertarget{classtk_1_1_semaphore_a66c5ac90338a6fcc6a9c2f22f1586de8}\index{tk::Semaphore@{tk::Semaphore}!Semaphore@{Semaphore}}
  34. \index{Semaphore@{Semaphore}!tk::Semaphore@{tk::Semaphore}}
  35. \doxysubsubsection{\texorpdfstring{Semaphore()}{Semaphore()}}
  36. {\footnotesize\ttfamily \label{classtk_1_1_semaphore_a66c5ac90338a6fcc6a9c2f22f1586de8}
  37. 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]}}
  38. セマフォを初期化します
  39. \begin{DoxyParams}{Parameters}
  40. {\em initial\+\_\+count} & 初期資源カウント (省略時: 1) \\
  41. \hline
  42. {\em max\+\_\+count} & 最大資源カウント (省略時: 1) \\
  43. \hline
  44. \end{DoxyParams}
  45. \label{classtk_1_1_semaphore_doc-func-members}
  46. \Hypertarget{classtk_1_1_semaphore_doc-func-members}
  47. \doxysubsection{Member Function Documentation}
  48. \Hypertarget{classtk_1_1_semaphore_a863ccee07bc701a78342c14503955d73}\index{tk::Semaphore@{tk::Semaphore}!acquire@{acquire}}
  49. \index{acquire@{acquire}!tk::Semaphore@{tk::Semaphore}}
  50. \doxysubsubsection{\texorpdfstring{acquire()}{acquire()}}
  51. {\footnotesize\ttfamily \label{classtk_1_1_semaphore_a863ccee07bc701a78342c14503955d73}
  52. void tk::\+\+Semaphore::\+acquire (\begin{DoxyParamCaption}{}{}\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}
  53. 資源を獲得するまで現在のタスクをブロックします
  54. 資源カウントが 0 以下の場合はタスクが休止状態になり、\+CPU は他タスクへ譲渡されます (CPU消費ゼロ)。 \Hypertarget{classtk_1_1_semaphore_ae53b9c57cc25fafb242a21776f112701}\index{tk::Semaphore@{tk::Semaphore}!count@{count}}
  55. \index{count@{count}!tk::Semaphore@{tk::Semaphore}}
  56. \doxysubsubsection{\texorpdfstring{count()}{count()}}
  57. {\footnotesize\ttfamily \label{classtk_1_1_semaphore_ae53b9c57cc25fafb242a21776f112701}
  58. int32\+\_\+t tk::\+\+Semaphore::\+count (\begin{DoxyParamCaption}{}{}\end{DoxyParamCaption}) const\hspace{0.3cm}{\ttfamily [inline]}}
  59. 現在の資源カウントを取得 \Hypertarget{classtk_1_1_semaphore_a7bb8eb8b0bd69b2f6b0a4d89d0f5b07b}\index{tk::Semaphore@{tk::Semaphore}!release@{release}}
  60. \index{release@{release}!tk::Semaphore@{tk::Semaphore}}
  61. \doxysubsubsection{\texorpdfstring{release()}{release()}}
  62. {\footnotesize\ttfamily \label{classtk_1_1_semaphore_a7bb8eb8b0bd69b2f6b0a4d89d0f5b07b}
  63. void tk::\+\+Semaphore::\+release (\begin{DoxyParamCaption}{}{}\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}
  64. 資源を返却し、待機中タスクがあれば最優先度のタスクを 1 つ起床させます
  65. \Hypertarget{classtk_1_1_semaphore_a3a246c8afc866dc438186d0a53cad5c2}\index{tk::Semaphore@{tk::Semaphore}!try\_acquire@{try\_acquire}}
  66. \index{try\_acquire@{try\_acquire}!tk::Semaphore@{tk::Semaphore}}
  67. \doxysubsubsection{\texorpdfstring{try\_acquire()}{try\_acquire()}}
  68. {\footnotesize\ttfamily \label{classtk_1_1_semaphore_a3a246c8afc866dc438186d0a53cad5c2}
  69. bool tk::\+\+Semaphore::\+try\+\_\+acquire (\begin{DoxyParamCaption}{}{}\end{DoxyParamCaption})\hspace{0.3cm}{\ttfamily [inline]}}
  70. 資源の獲得を試みます (ノンブロッキング)
  71. \begin{DoxyReturn}{Returns}
  72. true 獲得成功 (カウントが 1 減算された)
  73. false 資源がないため獲得失敗 (ブロックせず即座に復帰)
  74. \end{DoxyReturn}
  75. The documentation for this class was generated from the following file:\begin{DoxyCompactItemize}
  76. \item
  77. C:\+/\+\+Users/\+yoneda/\+\+Documents/\+\+Pico\+\_\+\+Projects/\+tinykernel/\+tinykernel/\+include/\+tinykernel/\doxymbox{\hyperlink{sync_8hpp}{sync.\+hpp}}\end{DoxyCompactItemize}