actor_8hpp_source.tex 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. \doxysection{actor.\+hpp}
  2. \hypertarget{actor_8hpp_source}{}\label{actor_8hpp_source}\index{C:/Users/yoneda/Documents/Pico\_Projects/tinykernel/tinykernel/include/tinykernel/actor.hpp@{C:/Users/yoneda/Documents/Pico\_Projects/tinykernel/tinykernel/include/tinykernel/actor.hpp}}
  3. \doxymbox{\hyperlink{actor_8hpp}{Go to the documentation of this file.}}
  4. \begin{DoxyCode}{0}
  5. \DoxyCodeLine{00001\ \textcolor{preprocessor}{\#pragma\ once}}
  6. \DoxyCodeLine{00002\ }
  7. \DoxyCodeLine{00003\ \textcolor{preprocessor}{\#include\ "{}\doxymbox{\hyperlink{kernel_8hpp}{kernel.hpp}}"{}}}
  8. \DoxyCodeLine{00004\ \textcolor{preprocessor}{\#include\ <cstdint>}}
  9. \DoxyCodeLine{00005\ \textcolor{preprocessor}{\#include\ <cstddef>}}
  10. \DoxyCodeLine{00006\ \textcolor{preprocessor}{\#include\ <type\_traits>}}
  11. \DoxyCodeLine{00007\ \textcolor{preprocessor}{\#include\ <utility>}}
  12. \DoxyCodeLine{00008\ }
  13. \DoxyCodeLine{00009\ \textcolor{keyword}{namespace\ }\doxymbox{\hyperlink{namespacetk}{tk}}\ \{}
  14. \DoxyCodeLine{00010\ }
  15. \DoxyCodeLine{00014\ \textcolor{keyword}{struct\ }\doxymbox{\hyperlink{structtk_1_1_message}{Message}}\ \{}
  16. \DoxyCodeLine{00015\ \ \ \ \ uint32\_t\ \doxymbox{\hyperlink{structtk_1_1_message_a9a7de43cbf3da1821cf18ae924f94c52}{id}};\ \ \ \ }
  17. \DoxyCodeLine{00016\ \ \ \ \ uintptr\_t\ \doxymbox{\hyperlink{structtk_1_1_message_a570c5c394d2786708ce4830e4087aa9e}{arg}};\ \ }
  18. \DoxyCodeLine{00017\ \};}
  19. \DoxyCodeLine{00018\ }
  20. \DoxyCodeLine{00028\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ MsgType,\ \textcolor{keywordtype}{size\_t}\ MaxSubscribers\ =\ 4>}
  21. \DoxyCodeLine{00029\ \textcolor{keyword}{class\ }\doxymbox{\hyperlink{classtk_1_1_event_hub}{EventHub}}\ \{}
  22. \DoxyCodeLine{00030\ \ \ \ \ \textcolor{keyword}{struct\ }Subscriber\ \{}
  23. \DoxyCodeLine{00031\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{void}*\ actor\{\textcolor{keyword}{nullptr}\};}
  24. \DoxyCodeLine{00032\ \ \ \ \ \ \ \ \ bool\ (*post\_fn)(\textcolor{keywordtype}{void}*,\ \textcolor{keyword}{const}\ MsgType\&)\{\textcolor{keyword}{nullptr}\};}
  25. \DoxyCodeLine{00033\ \ \ \ \ \};}
  26. \DoxyCodeLine{00034\ }
  27. \DoxyCodeLine{00035\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{inline}\ Subscriber\ subs\_[MaxSubscribers]\{\};}
  28. \DoxyCodeLine{00036\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keyword}{inline}\ \textcolor{keywordtype}{size\_t}\ count\_\{0\};}
  29. \DoxyCodeLine{00037\ }
  30. \DoxyCodeLine{00038\ \textcolor{keyword}{public}:}
  31. \DoxyCodeLine{00045\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keywordtype}{bool}\ \doxymbox{\hyperlink{classtk_1_1_event_hub_a50ebe29eaa2657604a1c85bf5125d490}{subscribe}}(\textcolor{keywordtype}{void}*\ actor,\ \textcolor{keywordtype}{bool}\ (*post\_fn)(\textcolor{keywordtype}{void}*,\ \textcolor{keyword}{const}\ MsgType\&))\ \{}
  32. \DoxyCodeLine{00046\ \ \ \ \ \ \ \ \ uint32\_t\ save\ =\ \doxymbox{\hyperlink{namespacetk_1_1detail_a5b8fa6406a867edf8c4410fcb03c6523}{detail::sched\_lock}}();}
  33. \DoxyCodeLine{00047\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (count\_\ >=\ MaxSubscribers)\ \{}
  34. \DoxyCodeLine{00048\ \ \ \ \ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{namespacetk_1_1detail_a80be9b2429346faf161eab01f595684b}{detail::sched\_unlock}}(save);}
  35. \DoxyCodeLine{00049\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{false};}
  36. \DoxyCodeLine{00050\ \ \ \ \ \ \ \ \ \}}
  37. \DoxyCodeLine{00051\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keywordtype}{size\_t}\ i\ =\ 0;\ i\ <\ count\_;\ ++i)\ \{}
  38. \DoxyCodeLine{00052\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (subs\_[i].actor\ ==\ actor)\ \{}
  39. \DoxyCodeLine{00053\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{namespacetk_1_1detail_a80be9b2429346faf161eab01f595684b}{detail::sched\_unlock}}(save);}
  40. \DoxyCodeLine{00054\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{true};\ \ \textcolor{comment}{//\ 登録済み}}
  41. \DoxyCodeLine{00055\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
  42. \DoxyCodeLine{00056\ \ \ \ \ \ \ \ \ \}}
  43. \DoxyCodeLine{00057\ \ \ \ \ \ \ \ \ subs\_[count\_++]\ =\ \{actor,\ post\_fn\};}
  44. \DoxyCodeLine{00058\ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{namespacetk_1_1detail_a80be9b2429346faf161eab01f595684b}{detail::sched\_unlock}}(save);}
  45. \DoxyCodeLine{00059\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{true};}
  46. \DoxyCodeLine{00060\ \ \ \ \ \}}
  47. \DoxyCodeLine{00061\ }
  48. \DoxyCodeLine{00067\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keywordtype}{bool}\ \doxymbox{\hyperlink{classtk_1_1_event_hub_a09c779ce8c594ea44c831adfd7e287f8}{unsubscribe}}(\textcolor{keywordtype}{void}*\ actor)\ \{}
  49. \DoxyCodeLine{00068\ \ \ \ \ \ \ \ \ uint32\_t\ save\ =\ \doxymbox{\hyperlink{namespacetk_1_1detail_a5b8fa6406a867edf8c4410fcb03c6523}{detail::sched\_lock}}();}
  50. \DoxyCodeLine{00069\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keywordtype}{size\_t}\ i\ =\ 0;\ i\ <\ count\_;\ ++i)\ \{}
  51. \DoxyCodeLine{00070\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (subs\_[i].actor\ ==\ actor)\ \{}
  52. \DoxyCodeLine{00071\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keywordtype}{size\_t}\ j\ =\ i;\ j\ +\ 1\ <\ count\_;\ ++j)\ \{}
  53. \DoxyCodeLine{00072\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ subs\_[j]\ =\ subs\_[j\ +\ 1];}
  54. \DoxyCodeLine{00073\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \}}
  55. \DoxyCodeLine{00074\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ count\_-\/-\/;}
  56. \DoxyCodeLine{00075\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{namespacetk_1_1detail_a80be9b2429346faf161eab01f595684b}{detail::sched\_unlock}}(save);}
  57. \DoxyCodeLine{00076\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{true};}
  58. \DoxyCodeLine{00077\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
  59. \DoxyCodeLine{00078\ \ \ \ \ \ \ \ \ \}}
  60. \DoxyCodeLine{00079\ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{namespacetk_1_1detail_a80be9b2429346faf161eab01f595684b}{detail::sched\_unlock}}(save);}
  61. \DoxyCodeLine{00080\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{false};}
  62. \DoxyCodeLine{00081\ \ \ \ \ \}}
  63. \DoxyCodeLine{00082\ }
  64. \DoxyCodeLine{00089\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keywordtype}{size\_t}\ \doxymbox{\hyperlink{classtk_1_1_event_hub_a3a59a641ad3fe121c0da7e1c81dc300b}{publish}}(\textcolor{keyword}{const}\ MsgType\&\ msg)\ \{}
  65. \DoxyCodeLine{00090\ \ \ \ \ \ \ \ \ Subscriber\ local\_subs[MaxSubscribers];}
  66. \DoxyCodeLine{00091\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{size\_t}\ n\ =\ 0;}
  67. \DoxyCodeLine{00092\ \ \ \ \ \ \ \ \ \{}
  68. \DoxyCodeLine{00093\ \ \ \ \ \ \ \ \ \ \ \ \ uint32\_t\ save\ =\ \doxymbox{\hyperlink{namespacetk_1_1detail_a5b8fa6406a867edf8c4410fcb03c6523}{detail::sched\_lock}}();}
  69. \DoxyCodeLine{00094\ \ \ \ \ \ \ \ \ \ \ \ \ n\ =\ count\_;}
  70. \DoxyCodeLine{00095\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keywordtype}{size\_t}\ i\ =\ 0;\ i\ <\ n;\ ++i)\ \{}
  71. \DoxyCodeLine{00096\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ local\_subs[i]\ =\ subs\_[i];}
  72. \DoxyCodeLine{00097\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
  73. \DoxyCodeLine{00098\ \ \ \ \ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{namespacetk_1_1detail_a80be9b2429346faf161eab01f595684b}{detail::sched\_unlock}}(save);}
  74. \DoxyCodeLine{00099\ \ \ \ \ \ \ \ \ \}}
  75. \DoxyCodeLine{00100\ }
  76. \DoxyCodeLine{00101\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{size\_t}\ delivered\ =\ 0;}
  77. \DoxyCodeLine{00102\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (\textcolor{keywordtype}{size\_t}\ i\ =\ 0;\ i\ <\ n;\ ++i)\ \{}
  78. \DoxyCodeLine{00103\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (local\_subs[i].post\_fn\ \&\&\ local\_subs[i].post\_fn(local\_subs[i].actor,\ msg))\ \{}
  79. \DoxyCodeLine{00104\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ delivered++;}
  80. \DoxyCodeLine{00105\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
  81. \DoxyCodeLine{00106\ \ \ \ \ \ \ \ \ \}}
  82. \DoxyCodeLine{00107\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ delivered;}
  83. \DoxyCodeLine{00108\ \ \ \ \ \}}
  84. \DoxyCodeLine{00109\ }
  85. \DoxyCodeLine{00111\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keywordtype}{size\_t}\ \doxymbox{\hyperlink{classtk_1_1_event_hub_ac4cd6ce4e37b74385c7f4352a5516930}{subscriber\_count}}()\ \{}
  86. \DoxyCodeLine{00112\ \ \ \ \ \ \ \ \ uint32\_t\ save\ =\ \doxymbox{\hyperlink{namespacetk_1_1detail_a5b8fa6406a867edf8c4410fcb03c6523}{detail::sched\_lock}}();}
  87. \DoxyCodeLine{00113\ \ \ \ \ \ \ \ \ \textcolor{keywordtype}{size\_t}\ n\ =\ count\_;}
  88. \DoxyCodeLine{00114\ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{namespacetk_1_1detail_a80be9b2429346faf161eab01f595684b}{detail::sched\_unlock}}(save);}
  89. \DoxyCodeLine{00115\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ n;}
  90. \DoxyCodeLine{00116\ \ \ \ \ \}}
  91. \DoxyCodeLine{00117\ \};}
  92. \DoxyCodeLine{00118\ }
  93. \DoxyCodeLine{00134\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ MsgType>}
  94. \DoxyCodeLine{00135\ \textcolor{keyword}{inline}\ \textcolor{keywordtype}{size\_t}\ \doxymbox{\hyperlink{namespacetk_a083495c9bf857a63f6c20a20aac0ca52}{publish}}(\textcolor{keyword}{const}\ MsgType\&\ msg)\ \{}
  95. \DoxyCodeLine{00136\ \ \ \ \ \textcolor{keywordflow}{return}\ \doxymbox{\hyperlink{classtk_1_1_event_hub_a3a59a641ad3fe121c0da7e1c81dc300b}{EventHub<MsgType>::publish}}(msg);}
  96. \DoxyCodeLine{00137\ \}}
  97. \DoxyCodeLine{00138\ }
  98. \DoxyCodeLine{00146\ \textcolor{keyword}{inline}\ \textcolor{keywordtype}{size\_t}\ \doxymbox{\hyperlink{namespacetk_a083495c9bf857a63f6c20a20aac0ca52}{publish}}(uint32\_t\ \textcolor{keywordtype}{id},\ uintptr\_t\ arg\ =\ 0)\ \{}
  99. \DoxyCodeLine{00147\ \ \ \ \ \textcolor{keywordflow}{return}\ \doxymbox{\hyperlink{namespacetk_a083495c9bf857a63f6c20a20aac0ca52}{publish}}(\doxymbox{\hyperlink{structtk_1_1_message}{Message}}\{id,\ arg\});}
  100. \DoxyCodeLine{00148\ \}}
  101. \DoxyCodeLine{00149\ }
  102. \DoxyCodeLine{00173\ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ MsgType\ =\ Message,\ \textcolor{keywordtype}{size\_t}\ QueueSize\ =\ 8>}
  103. \DoxyCodeLine{00174\ \textcolor{keyword}{class\ }\doxymbox{\hyperlink{classtk_1_1_actor_a776aef8cdcfb4416ef976697eb518ed5}{Actor}}\ \{}
  104. \DoxyCodeLine{00175\ \ \ \ \ \textcolor{keyword}{static\_assert}(QueueSize\ >\ 0,\ \textcolor{stringliteral}{"{}QueueSize\ must\ be\ greater\ than\ 0"{}});}
  105. \DoxyCodeLine{00176\ }
  106. \DoxyCodeLine{00177\ \textcolor{keyword}{public}:}
  107. \DoxyCodeLine{00178\ \ \ \ \ \doxymbox{\hyperlink{classtk_1_1_actor_a776aef8cdcfb4416ef976697eb518ed5}{Actor}}()\ =\ \textcolor{keywordflow}{default};}
  108. \DoxyCodeLine{00179\ \ \ \ \ \textcolor{keyword}{virtual}\ \doxymbox{\hyperlink{classtk_1_1_actor_abfc63a514a3ae7cdbdf9ceee81c3b0fc}{\string~Actor}}()\ \{}
  109. \DoxyCodeLine{00180\ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{classtk_1_1_event_hub_a09c779ce8c594ea44c831adfd7e287f8}{EventHub<MsgType>::unsubscribe}}(\textcolor{keyword}{this});}
  110. \DoxyCodeLine{00181\ \ \ \ \ \}}
  111. \DoxyCodeLine{00182\ }
  112. \DoxyCodeLine{00191\ \ \ \ \ \textcolor{keywordtype}{bool}\ \doxymbox{\hyperlink{classtk_1_1_actor_ac98ec3132f2ded910a6899b030c06f3f}{start}}(uint32\_t\ prio\ =\ \doxymbox{\hyperlink{namespacetk_a3d47fbd63b95ed3b46bed70c2fa1e50ea0e6779023b97999c2cef66ba1d4d1fca}{PRIO\_NORMAL}})\ \{}
  113. \DoxyCodeLine{00192\ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{classtk_1_1_event_hub_a50ebe29eaa2657604a1c85bf5125d490}{EventHub<MsgType>::subscribe}}(\textcolor{keyword}{this},\ [](\textcolor{keywordtype}{void}*\ obj,\ \textcolor{keyword}{const}\ MsgType\&\ m)\ \{}
  114. \DoxyCodeLine{00193\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{static\_cast<}\doxymbox{\hyperlink{classtk_1_1_actor_a776aef8cdcfb4416ef976697eb518ed5}{Actor<MsgType,\ QueueSize>}}*\textcolor{keyword}{>}(obj)-\/>\doxymbox{\hyperlink{classtk_1_1_actor_a224e6be4dca0d1500f2121e97bd0f92d}{post}}(m);}
  115. \DoxyCodeLine{00194\ \ \ \ \ \ \ \ \ \});}
  116. \DoxyCodeLine{00195\ \ \ \ \ \ \ \ \ handle\_\ =\ \doxymbox{\hyperlink{namespacetk_a6e721332f5a7d85998345ed218de7394}{tk::create}}(task\_entry,\ \textcolor{keyword}{this},\ prio);}
  117. \DoxyCodeLine{00196\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ handle\_.is\_valid();}
  118. \DoxyCodeLine{00197\ \ \ \ \ \}}
  119. \DoxyCodeLine{00198\ }
  120. \DoxyCodeLine{00207\ \ \ \ \ \textcolor{keywordtype}{bool}\ \doxymbox{\hyperlink{classtk_1_1_actor_a224e6be4dca0d1500f2121e97bd0f92d}{post}}(\textcolor{keyword}{const}\ MsgType\&\ msg)\ \{}
  121. \DoxyCodeLine{00208\ \ \ \ \ \ \ \ \ uint32\_t\ save\ =\ \doxymbox{\hyperlink{namespacetk_1_1detail_a5b8fa6406a867edf8c4410fcb03c6523}{detail::sched\_lock}}();}
  122. \DoxyCodeLine{00209\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (count\_\ >=\ QueueSize)\ \{}
  123. \DoxyCodeLine{00210\ \ \ \ \ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{namespacetk_1_1detail_a80be9b2429346faf161eab01f595684b}{detail::sched\_unlock}}(save);}
  124. \DoxyCodeLine{00211\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{false};}
  125. \DoxyCodeLine{00212\ \ \ \ \ \ \ \ \ \}}
  126. \DoxyCodeLine{00213\ \ \ \ \ \ \ \ \ queue\_[tail\_]\ =\ msg;}
  127. \DoxyCodeLine{00214\ \ \ \ \ \ \ \ \ tail\_\ =\ (tail\_\ +\ 1)\ \%\ QueueSize;}
  128. \DoxyCodeLine{00215\ \ \ \ \ \ \ \ \ count\_++;}
  129. \DoxyCodeLine{00216\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (waiting\_)\ \{}
  130. \DoxyCodeLine{00217\ \ \ \ \ \ \ \ \ \ \ \ \ waiting\_\ =\ \textcolor{keyword}{false};}
  131. \DoxyCodeLine{00218\ \ \ \ \ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{namespacetk_1_1detail_ab19385598f18560cb574cc86174ececa}{detail::wake\_task\_locked}}(handle\_);}
  132. \DoxyCodeLine{00219\ \ \ \ \ \ \ \ \ \}}
  133. \DoxyCodeLine{00220\ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{namespacetk_1_1detail_a80be9b2429346faf161eab01f595684b}{detail::sched\_unlock}}(save);}
  134. \DoxyCodeLine{00221\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{true};}
  135. \DoxyCodeLine{00222\ \ \ \ \ \}}
  136. \DoxyCodeLine{00223\ }
  137. \DoxyCodeLine{00230\ \ \ \ \ \textcolor{keywordtype}{bool}\ \doxymbox{\hyperlink{classtk_1_1_actor_a863f28d824aaa78c75789166b1c2a010}{post}}(MsgType\&\&\ msg)\ \{}
  138. \DoxyCodeLine{00231\ \ \ \ \ \ \ \ \ uint32\_t\ save\ =\ \doxymbox{\hyperlink{namespacetk_1_1detail_a5b8fa6406a867edf8c4410fcb03c6523}{detail::sched\_lock}}();}
  139. \DoxyCodeLine{00232\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (count\_\ >=\ QueueSize)\ \{}
  140. \DoxyCodeLine{00233\ \ \ \ \ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{namespacetk_1_1detail_a80be9b2429346faf161eab01f595684b}{detail::sched\_unlock}}(save);}
  141. \DoxyCodeLine{00234\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{false};}
  142. \DoxyCodeLine{00235\ \ \ \ \ \ \ \ \ \}}
  143. \DoxyCodeLine{00236\ \ \ \ \ \ \ \ \ queue\_[tail\_]\ =\ std::move(msg);}
  144. \DoxyCodeLine{00237\ \ \ \ \ \ \ \ \ tail\_\ =\ (tail\_\ +\ 1)\ \%\ QueueSize;}
  145. \DoxyCodeLine{00238\ \ \ \ \ \ \ \ \ count\_++;}
  146. \DoxyCodeLine{00239\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{if}\ (waiting\_)\ \{}
  147. \DoxyCodeLine{00240\ \ \ \ \ \ \ \ \ \ \ \ \ waiting\_\ =\ \textcolor{keyword}{false};}
  148. \DoxyCodeLine{00241\ \ \ \ \ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{namespacetk_1_1detail_ab19385598f18560cb574cc86174ececa}{detail::wake\_task\_locked}}(handle\_);}
  149. \DoxyCodeLine{00242\ \ \ \ \ \ \ \ \ \}}
  150. \DoxyCodeLine{00243\ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{namespacetk_1_1detail_a80be9b2429346faf161eab01f595684b}{detail::sched\_unlock}}(save);}
  151. \DoxyCodeLine{00244\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \textcolor{keyword}{true};}
  152. \DoxyCodeLine{00245\ \ \ \ \ \}}
  153. \DoxyCodeLine{00246\ }
  154. \DoxyCodeLine{00254\ \ \ \ \ \textcolor{keyword}{template}\ <\textcolor{keyword}{typename}\ U\ =\ MsgType>}
  155. \DoxyCodeLine{00255\ \ \ \ \ \textcolor{keyword}{typename}\ std::enable\_if<std::is\_same<U,\ Message>::value,\ \textcolor{keywordtype}{bool}>::type}
  156. \DoxyCodeLine{00256\ \ \ \ \ \doxymbox{\hyperlink{classtk_1_1_actor_a5c4f4f2f1b8011a37773617e34218c2d}{post}}(uint32\_t\ \textcolor{keywordtype}{id},\ uintptr\_t\ arg\ =\ 0)\ \{}
  157. \DoxyCodeLine{00257\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{return}\ \doxymbox{\hyperlink{classtk_1_1_actor_a224e6be4dca0d1500f2121e97bd0f92d}{post}}(\doxymbox{\hyperlink{structtk_1_1_message}{Message}}\{id,\ arg\});}
  158. \DoxyCodeLine{00258\ \ \ \ \ \}}
  159. \DoxyCodeLine{00259\ }
  160. \DoxyCodeLine{00261\ \ \ \ \ \doxymbox{\hyperlink{structtk_1_1_task_handle}{TaskHandle}}\ \doxymbox{\hyperlink{classtk_1_1_actor_a60a2752360fa7185ec7776f2a6ef766a}{handle}}()\textcolor{keyword}{\ const\ }\{\ \textcolor{keywordflow}{return}\ handle\_;\ \}}
  161. \DoxyCodeLine{00262\ }
  162. \DoxyCodeLine{00263\ \textcolor{keyword}{protected}:}
  163. \DoxyCodeLine{00270\ \ \ \ \ \textcolor{keyword}{virtual}\ \textcolor{keywordtype}{void}\ \doxymbox{\hyperlink{classtk_1_1_actor_afb31ec0d50d1ac97e6a4ce148a96f78d}{on\_start}}()\ \{\}}
  164. \DoxyCodeLine{00271\ }
  165. \DoxyCodeLine{00280\ \ \ \ \ \textcolor{keyword}{virtual}\ \textcolor{keywordtype}{void}\ \doxymbox{\hyperlink{classtk_1_1_actor_a1147554d6ddb64d822285ca5a03506a4}{on\_message}}(\textcolor{keyword}{const}\ MsgType\&\ msg)\ =\ 0;}
  166. \DoxyCodeLine{00281\ }
  167. \DoxyCodeLine{00282\ \textcolor{keyword}{private}:}
  168. \DoxyCodeLine{00283\ \ \ \ \ \textcolor{keyword}{static}\ \textcolor{keywordtype}{void}\ task\_entry(\textcolor{keywordtype}{void}*\ arg)\ \{}
  169. \DoxyCodeLine{00284\ \ \ \ \ \ \ \ \ \textcolor{keyword}{static\_cast<}\doxymbox{\hyperlink{classtk_1_1_actor_a776aef8cdcfb4416ef976697eb518ed5}{Actor<MsgType,\ QueueSize>}}*\textcolor{keyword}{>}(arg)-\/>event\_loop();}
  170. \DoxyCodeLine{00285\ \ \ \ \ \}}
  171. \DoxyCodeLine{00286\ }
  172. \DoxyCodeLine{00287\ \ \ \ \ \textcolor{keywordtype}{void}\ event\_loop()\ \{}
  173. \DoxyCodeLine{00288\ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{classtk_1_1_actor_afb31ec0d50d1ac97e6a4ce148a96f78d}{on\_start}}();}
  174. \DoxyCodeLine{00289\ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{for}\ (;;)\ \{}
  175. \DoxyCodeLine{00290\ \ \ \ \ \ \ \ \ \ \ \ \ MsgType\ msg\{\};}
  176. \DoxyCodeLine{00291\ \ \ \ \ \ \ \ \ \ \ \ \ uint32\_t\ save\ =\ \doxymbox{\hyperlink{namespacetk_1_1detail_a5b8fa6406a867edf8c4410fcb03c6523}{detail::sched\_lock}}();}
  177. \DoxyCodeLine{00292\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{keywordflow}{while}\ (count\_\ ==\ 0)\ \{}
  178. \DoxyCodeLine{00293\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ waiting\_\ =\ \textcolor{keyword}{true};}
  179. \DoxyCodeLine{00294\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{namespacetk_1_1detail_a400363f36b5fb5dfc8aec11334471d0d}{detail::block\_current\_task\_locked}}();}
  180. \DoxyCodeLine{00295\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{namespacetk_1_1detail_a80be9b2429346faf161eab01f595684b}{detail::sched\_unlock}}(save);}
  181. \DoxyCodeLine{00296\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ コンテキストスイッチされ、他のタスクが走る。}}
  182. \DoxyCodeLine{00297\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ wake\_task\_locked\ で起こされたらここに戻る。}}
  183. \DoxyCodeLine{00298\ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ \ save\ =\ \doxymbox{\hyperlink{namespacetk_1_1detail_a5b8fa6406a867edf8c4410fcb03c6523}{detail::sched\_lock}}();}
  184. \DoxyCodeLine{00299\ \ \ \ \ \ \ \ \ \ \ \ \ \}}
  185. \DoxyCodeLine{00300\ \ \ \ \ \ \ \ \ \ \ \ \ msg\ =\ std::move(queue\_[head\_]);}
  186. \DoxyCodeLine{00301\ \ \ \ \ \ \ \ \ \ \ \ \ head\_\ =\ (head\_\ +\ 1)\ \%\ QueueSize;}
  187. \DoxyCodeLine{00302\ \ \ \ \ \ \ \ \ \ \ \ \ count\_-\/-\/;}
  188. \DoxyCodeLine{00303\ \ \ \ \ \ \ \ \ \ \ \ \ waiting\_\ =\ \textcolor{keyword}{false};}
  189. \DoxyCodeLine{00304\ \ \ \ \ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{namespacetk_1_1detail_a80be9b2429346faf161eab01f595684b}{detail::sched\_unlock}}(save);}
  190. \DoxyCodeLine{00305\ }
  191. \DoxyCodeLine{00306\ \ \ \ \ \ \ \ \ \ \ \ \ \textcolor{comment}{//\ メッセージディスパッチ(ロック解除状態で実行)}}
  192. \DoxyCodeLine{00307\ \ \ \ \ \ \ \ \ \ \ \ \ \doxymbox{\hyperlink{classtk_1_1_actor_a1147554d6ddb64d822285ca5a03506a4}{on\_message}}(msg);}
  193. \DoxyCodeLine{00308\ \ \ \ \ \ \ \ \ \}}
  194. \DoxyCodeLine{00309\ \ \ \ \ \}}
  195. \DoxyCodeLine{00310\ }
  196. \DoxyCodeLine{00311\ \ \ \ \ MsgType\ queue\_[QueueSize]\{\};}
  197. \DoxyCodeLine{00312\ \ \ \ \ \textcolor{keywordtype}{size\_t}\ head\_\{0\};}
  198. \DoxyCodeLine{00313\ \ \ \ \ \textcolor{keywordtype}{size\_t}\ tail\_\{0\};}
  199. \DoxyCodeLine{00314\ \ \ \ \ \textcolor{keywordtype}{size\_t}\ count\_\{0\};}
  200. \DoxyCodeLine{00315\ \ \ \ \ \textcolor{keywordtype}{bool}\ waiting\_\{\textcolor{keyword}{false}\};}
  201. \DoxyCodeLine{00316\ \ \ \ \ TaskHandle\ handle\_\{\};}
  202. \DoxyCodeLine{00317\ \};}
  203. \DoxyCodeLine{00318\ }
  204. \DoxyCodeLine{00319\ \}\ \ \textcolor{comment}{//\ namespace\ tk}}
  205. \end{DoxyCode}