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
00052 #ifndef TOPPERS_KERNELSTATUS_HPP_
00053 #define TOPPERS_KERNELSTATUS_HPP_
00054
00055 #include <toppers/object.hpp>
00056
00057 namespace toppers
00058 {
00059
00060 template <class Diagnostics, class Stub> class readyqueue;
00061 template <class Diagnostics, class Stub> class cpulock;
00062 template <class Diagnostics, class Stub> class dispacher;
00063
00073 template <class Diagnostics = TOPPERS_DEFAULT_DIAGNOSTICS,
00074 class Stub = TOPPERS_DEFAULT_STUB >
00075 class kernelstatus : Diagnostics
00076 {
00077 public:
00079 typedef t_rsys system_reference;
00081 typedef t_rver version_reference;
00083 typedef t_rcfg configuration_reference;
00085 typedef system_reference reference;
00086
00087 struct context;
00088
00090 static ER refer(system_reference* pk_robj)
00091 {
00092 ER ercd = Stub::stub_ref_sys(pk_robj);
00093 return static_handle_error(ercd);
00094 }
00096 static ER refer(version_reference* pk_robj)
00097 {
00098 ER ercd = Stub::stub_ref_ver(pk_robj);
00099 return static_handle_error(ercd);
00100 }
00102 static ER refer(configuration_reference* pk_robj)
00103 {
00104 ER ercd = Stub::stub_ref_cfg(pk_robj);
00105 return static_handle_error(ercd);
00106 }
00107 };
00108
00117 template <class Diagnostics, class Stub>
00118 struct kernelstatus<Diagnostics, Stub>::context
00119 {
00121 static bool sense()
00122 {
00123 return Stub::stub_sns_ctx();
00124 }
00125 };
00126
00127
00136 template <class Diagnostics = TOPPERS_DEFAULT_DIAGNOSTICS,
00137 class Stub = TOPPERS_DEFAULT_STUB >
00138 class readyqueue : Diagnostics
00139 {
00140 public:
00142 static ER rotate(PRI tskpri, task_context_tag = task_context)
00143 {
00144 ER ercd = Stub::stub_rot_rdq(tskpri);
00145 return static_handle_error(ercd);
00146 }
00148 static ER rotate(PRI tskpri, non_task_context_tag)
00149 {
00150 ER ercd = Stub::stub_irot_rdq(tskpri);
00151 return static_handle_error(ercd);
00152 }
00154 static ER rotate(PRI tskpri, context_independent_tag)
00155 {
00156 ER ercd;
00157 if (Stub::stub_sns_ctx())
00158 ercd = Stub::stub_irot_rdq(tskpri);
00159 else
00160 ercd = Stub::stub_rot_rdq(tskpri);
00161 return static_handle_error(ercd);
00162 }
00163 };
00164
00173 template <class Diagnostics = TOPPERS_DEFAULT_DIAGNOSTICS,
00174 class Stub = TOPPERS_DEFAULT_STUB >
00175 class cpulock : Diagnostics
00176 {
00177 public:
00179 static bool sense()
00180 {
00181 return Stub::stub_sns_loc();
00182 }
00184 static ER lock(task_context_tag = task_context)
00185 {
00186 ER ercd = Stub::stub_loc_cpu();
00187 return static_handle_error(ercd);
00188 }
00190 static ER lock(non_task_context_tag)
00191 {
00192 ER ercd = Stub::stub_iloc_cpu();
00193 return static_handle_error(ercd);
00194 }
00196 static ER lock(context_independent_tag)
00197 {
00198 ER ercd;
00199 if (Stub::stub_sns_ctx())
00200 ercd = Stub::stub_iloc_cpu();
00201 else
00202 ercd = Stub::stub_loc_cpu();
00203 return static_handle_error(ercd);
00204 }
00206 static ER unlock(task_context_tag = task_context)
00207 {
00208 ER ercd = Stub::stub_unl_cpu();
00209 return static_handle_error(ercd);
00210 }
00212 static ER unlock(non_task_context_tag)
00213 {
00214 ER ercd = Stub::stub_iunl_cpu();
00215 return static_handle_error(ercd);
00216 }
00218 static ER unlock(context_independent_tag)
00219 {
00220 ER ercd;
00221 if (Stub::stub_sns_ctx())
00222 ercd = Stub::stub_iunl_cpu();
00223 else
00224 ercd = Stub::stub_unl_cpu();
00225 return static_handle_error(ercd);
00226 }
00227 };
00228
00229 namespace detail
00230 {
00231
00232 template <bool SenseKernel, class LockObj> class lock_helper;
00233
00234 template <bool SenseKernel, class Diagnostics, class Stub>
00235 class lock_helper<SenseKernel, cpulock<Diagnostics, Stub> >
00236 {
00237 public:
00238 typedef cpulock<Diagnostics, Stub> sync_type;
00239
00240 static bool sense(const sync_type& sync)
00241 {
00242 return sense_kernel<SenseKernel>() ? true : sync_type::sense();
00243 }
00244 static ER lock(const sync_type& sync)
00245 {
00246 return sense_kernel<SenseKernel>() ? E_OK : sync_type::lock();
00247 }
00248 static ER unlock(const sync_type& sync)
00249 {
00250 return sense_kernel<SenseKernel>() ? E_OK : sync_type::unlock();
00251 }
00252 };
00253
00254 }
00255
00256
00264 template <class Diagnostics = TOPPERS_DEFAULT_DIAGNOSTICS,
00265 class Stub = TOPPERS_DEFAULT_STUB >
00266 class dispatcher : Diagnostics
00267 {
00268 public:
00269 struct pending;
00270
00272 static bool sense()
00273 {
00274 return Stub::stub_sns_dsp();
00275 }
00277 static ER disable()
00278 {
00279 ER ercd = Stub::stub_dis_dsp();
00280 return static_handle_error(ercd);
00281 }
00283 static ER enable()
00284 {
00285 ER ercd = Stub::stub_ena_dsp();
00286 return static_handle_error(ercd);
00287 }
00288 };
00289
00297 template <class Diagnostics, class Stub>
00298 struct dispatcher<Diagnostics, Stub>::pending
00299 {
00300 static bool sense()
00301 {
00302 return Stub::stub_sns_dpn();
00303 }
00304 };
00305
00306 namespace detail
00307 {
00308
00309 template <bool SenseKernel, class LockObj> class lock_helper;
00310
00311 template <bool SenseKernel, class Diagnostics, class Stub>
00312 class lock_helper<SenseKernel, dispatcher<Diagnostics, Stub> >
00313 {
00314 public:
00315 typedef dispatcher<Diagnostics, Stub> sync_type;
00316
00317 static bool sense(const sync_type& sync)
00318 {
00319 return sense_kernel<SenseKernel>() ? true : sync_type::sense();
00320 }
00321 static ER lock(const sync_type& sync)
00322 {
00323 return sense_kernel<SenseKernel>() ? E_OK : sync_type::disable();
00324 }
00325 static ER unlock(const sync_type& sync)
00326 {
00327 return sense_kernel<SenseKernel>() ? E_OK : sync_type::enable();
00328 }
00329 };
00330
00331 }
00332
00333 }
00334
00335 #endif // ! TOPPERS_KERNELSTATUS_HPP_