space_multi_thread_balance_quantity.h
Go to the documentation of this file.
1 
7 #ifndef SPACE_MULTI_THREAD_BALANCE_QUANTITY_H
8 #define SPACE_MULTI_THREAD_BALANCE_QUANTITY_H
9 
10 #include <argos3/core/simulator/space/space.h>
11 #include <pthread.h>
12 
13 namespace argos {
14 
16 
17  /****************************************/
18  /****************************************/
19 
20  private:
21 
22  struct SUpdateThreadData {
23  UInt32 ThreadId;
25 
26  SUpdateThreadData(UInt32 un_thread_id,
28  ThreadId(un_thread_id),
29  Space(pc_space) {}
30  };
31 
32  /****************************************/
33  /****************************************/
34 
35  private:
36 
38  SUpdateThreadData** m_psUpdateThreadData;
39 
41  pthread_t* m_ptUpdateThreads;
42 
44  UInt32 m_unSenseControlStepPhaseDoneCounter;
45  UInt32 m_unActPhaseDoneCounter;
46  UInt32 m_unPhysicsPhaseDoneCounter;
47  UInt32 m_unMediaPhaseDoneCounter;
48  UInt32 m_unEntityIterPhaseDoneCounter;
49 
51  pthread_mutex_t m_tSenseControlStepConditionalMutex;
52  pthread_mutex_t m_tActConditionalMutex;
53  pthread_mutex_t m_tPhysicsConditionalMutex;
54  pthread_mutex_t m_tMediaConditionalMutex;
55  pthread_mutex_t m_tEntityIterConditionalMutex;
56 
58  pthread_cond_t m_tSenseControlStepConditional;
59  pthread_cond_t m_tActConditional;
60  pthread_cond_t m_tPhysicsConditional;
61  pthread_cond_t m_tMediaConditional;
62  pthread_cond_t m_tEntityIterConditional;
63 
66  bool m_bIsControllableEntityAssignmentRecalculationNeeded;
67 
68  public:
69 
72 
73  virtual void Init(TConfigurationNode& t_tree);
74  virtual void Destroy();
75 
76  virtual void UpdateControllableEntitiesAct();
77  virtual void UpdatePhysics();
78  virtual void UpdateMedia();
81  const TControllableEntityIterCBType& c_cb);
82 
83  protected:
84 
85  virtual void AddControllableEntity(CControllableEntity& c_entity);
86  virtual void RemoveControllableEntity(CControllableEntity& c_entity);
87 
88  private:
89 
90  void StartThreads();
91  void UpdateThread(UInt32 un_id);
92 
97  void UpdateThreadEntityAct(UInt32 un_id, CRange<size_t>& c_range);
98 
103  void UpdateThreadPhysics(const CRange<size_t>& c_range);
104 
109  void UpdateThreadMedia(const CRange<size_t>& c_range);
110 
119  void UpdateThreadIterateOverEntities(UInt32 un_id, CRange<size_t>& c_range);
120 
126  void UpdateThreadEntitySenseControl(UInt32 un_id, CRange<size_t>& c_range);
127 
128  virtual void ControllableEntityIterationWaitAbort();
129 
130  friend void* LaunchUpdateThreadBalanceQuantity(void* p_data);
131 
132  };
133 
134 }
135 
136 #endif
unsigned int UInt32
32-bit unsigned integer.
Definition: datatypes.h:97
The namespace containing all the ARGoS related code.
Definition: ci_actuator.h:12
ticpp::Element TConfigurationNode
The ARGoS configuration XML node.
An entity that contains a pointer to the user-defined controller.
std::function< void(CControllableEntity *)> TControllableEntityIterCBType
The callback type for iteration over controllable entities within the PreStep() and/or PostStep() par...
Definition: space.h:90
virtual void AddControllableEntity(CControllableEntity &c_entity)
virtual void Destroy()
Destroys the space and all its entities.
virtual void Init(TConfigurationNode &t_tree)
Initializes the space using the <arena> section of the XML configuration file.
virtual void IterateOverControllableEntities(const TControllableEntityIterCBType &c_cb)
Given a callback specified in the loop functions, iterate over all controllable entities currently pr...
virtual void RemoveControllableEntity(CControllableEntity &c_entity)