Implements rudimentary thread-safety for EventBus and Logger classes.
This commit is contained in:
1 parent
34e1dd0c33
commit
fb35fbd350
6 files changed
+66
-31
No files matched your search
@@ -5,6 +5,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
#include <mutex>
|
||||
|
||||
namespace Plains {
|
||||
namespace Core {
|
||||
@@ -12,6 +13,7 @@ namespace Core {
|
||||
using std::thread;
|
||||
using std::string;
|
||||
using std::vector;
|
||||
using std::mutex;
|
||||
using std::unique_ptr;
|
||||
|
||||
class EventSubscriber {
|
||||
@@ -30,6 +32,7 @@ class Event {
|
||||
private:
|
||||
const string _id;
|
||||
vector<EventSubscriber*> _subscribers;
|
||||
mutex _mutex;
|
||||
};
|
||||
|
||||
class EventBus {
|
||||
@@ -38,12 +41,14 @@ class EventBus {
|
||||
~EventBus();
|
||||
Event& registerEvent(const string& eventID);
|
||||
|
||||
private:
|
||||
void run();
|
||||
|
||||
private:
|
||||
Logger& _logger;
|
||||
thread _thread;
|
||||
vector<Event*> _events;
|
||||
|
||||
void run();
|
||||
mutex _mutex;
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
Reference in new issue
Block a user