]> git.stg.codes - stg.git/blobdiff - projects/stargazer/actions.h
Use std::jthread and C++17.
[stg.git] / projects / stargazer / actions.h
index 6c1fc8a8c671ea9c7ed24781af0ff867990d09bb..33c9a8fdb4b57e282ddb832f4d075cbddf727e1c 100644 (file)
@@ -13,9 +13,9 @@
 //
 // actionsList.InvokeAll();
 
-#include <pthread.h>
-#include <list>
+#include <vector>
 #include <functional>
+#include <mutex>
 
 // Generalized actor type - a method of some class with one argument
 template <class ACTIVE_CLASS, typename DATA_TYPE>
@@ -41,8 +41,8 @@ public:
     ACTION(ACTIVE_CLASS & ac,
            typename ACTOR<ACTIVE_CLASS, DATA_TYPE>::TYPE a,
            DATA_TYPE d)
-        : activeClass(ac), actor(a), data(d) {};
-    void Invoke();
+        : activeClass(ac), actor(a), data(d) {}
+    void Invoke() override;
 private:
     ACTION(const ACTION<ACTIVE_CLASS, DATA_TYPE> & rvalue);
     ACTION<ACTIVE_CLASS, DATA_TYPE> & operator=(const ACTION<ACTIVE_CLASS, DATA_TYPE> & rvalue);
@@ -54,11 +54,11 @@ private:
 
 // A list of an actions
 // All methods are thread-safe
-class ACTIONS_LIST : private std::list<BASE_ACTION *>
+class ACTIONS_LIST : private std::vector<BASE_ACTION *>
 {
 public:
     // Just a typedef for parent class
-    typedef std::list<BASE_ACTION *> parent;
+    typedef std::vector<BASE_ACTION *> parent;
 
     // Initialize mutex
     ACTIONS_LIST();
@@ -82,7 +82,7 @@ public:
     // Invoke all actions in the list
     void InvokeAll();
 private:
-    mutable pthread_mutex_t mutex;
+    mutable std::mutex m_mutex;
 };
 
 #include "actions.inl.h"