No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

65 líneas
1.7 KiB

  1. #pragma once
  2. #include <ecs/config.h>
  3. #include <ecs/core/system/data_proxy.h>
  4. namespace ecs {
  5. namespace core {
  6. namespace system {
  7. namespace parallelism {
  8. struct none
  9. {
  10. public:
  11. template<typename T_context, typename T_instance>
  12. struct executor_proxy
  13. {
  14. public:
  15. using context_type = T_context;
  16. using instance_type = T_instance;
  17. context_type& context;
  18. instance_type& instance;
  19. public:
  20. template<typename T_func>
  21. inline void for_subtasks(T_func&& func)
  22. {
  23. instance.prepare_states(1);
  24. auto data = data_proxy::make_single(context, instance);
  25. std::forward<T_func>(func)(data);
  26. }
  27. };
  28. private:
  29. #ifndef NDEBUG
  30. bool _bound { false };
  31. mutable std::thread::id _thread_id { 0 };
  32. #endif
  33. public:
  34. #ifndef NDEBUG
  35. none(bool bound)
  36. : _bound(bound)
  37. { }
  38. #else
  39. none()
  40. { }
  41. #endif
  42. template<typename T_context, typename T_instance, typename T_func>
  43. inline void operator()(T_context& context, T_instance& instance, T_func&& func) const
  44. {
  45. #ifndef NDEBUG
  46. assert( !_bound
  47. && ( _thread_id == std::thread::id { 0 }
  48. || _thread_id == std::this_thread::get_id()));
  49. _thread_id = std::this_thread::get_id();
  50. #endif
  51. executor_proxy<T_context, T_instance> ep { context, instance };
  52. std::forward<T_func>(func)(instance, ep);
  53. }
  54. };
  55. } } } }