00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00051 #ifndef TOPPERS_CONTEXT_HPP_
00052 #define TOPPERS_CONTEXT_HPP_
00053
00054 #include <toppers/object.hpp>
00055
00056 namespace toppers
00057 {
00058
00071 template <class Diagnostics, class Stub>
00072 class task_context_body : protected Diagnostics
00073 {
00074 VP_INT exinf_;
00075
00076 public:
00078 void run() {}
00079
00081 VP_INT get_extended_info() const { return exinf_; }
00082
00084 static ER sleep(forever_tag = forever)
00085 {
00086 ER ercd = Stub::stub_slp_tsk();
00087 return static_handle_error(ercd);
00088 }
00090 static ER sleep(TMO tmout)
00091 {
00092 ER ercd = Stub::stub_tslp_tsk(tmout);
00093 return static_handle_error(ercd);
00094 }
00095
00097 static ER delay(RELTIM dlytim)
00098 {
00099 ER ercd = Stub::stub_dly_tsk(dlytim);
00100 return static_handle_error(ercd);
00101 }
00102
00104 static ER yield()
00105 {
00106 ER ercd = Stub::stub_dly_tsk(0);
00107 return static_handle_error(ercd);
00108 }
00109
00111 static const task_context_tag task_context = toppers::task_context;
00113 static const non_task_context_tag non_task_context = toppers::non_task_context;
00115 static const task_context_tag context_independent = toppers::task_context;
00116
00117 protected:
00119 typedef Stub stub;
00120
00122 task_context_body(VP_INT exinf) : exinf_(exinf) {}
00124 ~task_context_body() {}
00125
00127 static ID get_task_id()
00128 {
00129 ID tskid;
00130 Stub::stub_get_tid(&tskid);
00131 return tskid;
00132 }
00133
00134 private:
00135 task_context_body(const task_context_body<Diagnostics, Stub>&);
00136 task_context_body<Diagnostics, Stub>& operator=(const task_context_body<Diagnostics, Stub>&);
00137
00138 static ER sleep(polling_tag);
00139 };
00140
00152 template <class Diagnostics, class Stub>
00153 class non_task_context_body : protected Diagnostics
00154 {
00155 TOPPERS_STATIC_ASSERT(!Diagnostics::use_exception);
00156
00157 public:
00159 void run();
00160
00162 static const task_context_tag task_context = toppers::task_context;
00164 static const non_task_context_tag non_task_context = toppers::non_task_context;
00166 static const non_task_context_tag context_independent = toppers::non_task_context;
00167
00168 protected:
00170 typedef Stub stub;
00171
00173 non_task_context_body() {}
00175 ~non_task_context_body() {}
00176
00178 static ID get_task_id()
00179 {
00180 ID tskid;
00181 Stub::stub_iget_tid(&tskid);
00182 return tskid;
00183 }
00184
00185 private:
00186 non_task_context_body(const non_task_context_body<Diagnostics, Stub>&);
00187 non_task_context_body<Diagnostics, Stub>& operator=(const non_task_context_body<Diagnostics, Stub>&);
00188 };
00189
00190 namespace detail
00191 {
00192
00193 template <typename Func, Func Routine, typename R, typename T>
00194 inline void (*bind_context_handler(R (*func)(T)))(VP_INT)
00195 {
00196 struct _
00197 {
00198 static void handler(VP_INT exinf)
00199 {
00200 (*(R(*)(T))Routine)(T(exinf));
00201 }
00202 };
00203 return &_::handler;
00204 }
00205
00206 }
00207
00208 }
00209
00210 #endif // ! TOPPERS_CONTEXT_HPP_