TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MapUpdater Class Reference

#include <MapUpdater.h>

Public Member Functions

 MapUpdater ()
 
 ~MapUpdater ()
 
void schedule_update (Map &map, uint32 diff)
 
void wait ()
 
void activate (size_t num_threads)
 
void deactivate ()
 
bool activated ()
 

Private Member Functions

void update_finished ()
 
void WorkerThread ()
 

Private Attributes

ProducerConsumerQueue
< MapUpdateRequest * > 
_queue
 
std::vector< std::thread > _workerThreads
 
std::atomic< bool_cancelationToken
 
std::mutex _lock
 
std::condition_variable _condition
 
size_t pending_requests
 

Friends

class MapUpdateRequest
 

Constructor & Destructor Documentation

MapUpdater::MapUpdater ( )
inline
35 : _cancelationToken(false), pending_requests(0) {}
size_t pending_requests
Definition: MapUpdater.h:59
std::atomic< bool > _cancelationToken
Definition: MapUpdater.h:55
MapUpdater::~MapUpdater ( )
inline
36 { };

Member Function Documentation

void MapUpdater::activate ( size_t  num_threads)
48 {
49  for (size_t i = 0; i < num_threads; ++i)
50  {
51  _workerThreads.push_back(std::thread(&MapUpdater::WorkerThread, this));
52  }
53 }
std::vector< std::thread > _workerThreads
Definition: MapUpdater.h:54
void WorkerThread()
Definition: MapUpdater.cpp:102

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool MapUpdater::activated ( )
89 {
90  return _workerThreads.size() > 0;
91 }
std::vector< std::thread > _workerThreads
Definition: MapUpdater.h:54

+ Here is the caller graph for this function:

void MapUpdater::deactivate ( )
56 {
57  _cancelationToken = true;
58 
59  wait();
60 
61  _queue.Cancel();
62 
63  for (auto& thread : _workerThreads)
64  {
65  thread.join();
66  }
67 }
std::vector< std::thread > _workerThreads
Definition: MapUpdater.h:54
std::atomic< bool > _cancelationToken
Definition: MapUpdater.h:55
void Cancel()
Definition: ProducerConsumerQueue.h:86
void wait()
Definition: MapUpdater.cpp:69
ProducerConsumerQueue< MapUpdateRequest * > _queue
Definition: MapUpdater.h:52

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void MapUpdater::schedule_update ( Map map,
uint32  diff 
)
80 {
81  std::lock_guard<std::mutex> lock(_lock);
82 
84 
85  _queue.Push(new MapUpdateRequest(map, *this, diff));
86 }
size_t pending_requests
Definition: MapUpdater.h:59
friend class MapUpdateRequest
Definition: MapUpdater.h:36
std::mutex _lock
Definition: MapUpdater.h:57
void Push(const T &value)
Definition: ProducerConsumerQueue.h:40
ProducerConsumerQueue< MapUpdateRequest * > _queue
Definition: MapUpdater.h:52

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void MapUpdater::update_finished ( )
private
94 {
95  std::lock_guard<std::mutex> lock(_lock);
96 
98 
99  _condition.notify_all();
100 }
size_t pending_requests
Definition: MapUpdater.h:59
std::mutex _lock
Definition: MapUpdater.h:57
std::condition_variable _condition
Definition: MapUpdater.h:58

+ Here is the caller graph for this function:

void MapUpdater::wait ( )
70 {
71  std::unique_lock<std::mutex> lock(_lock);
72 
73  while (pending_requests > 0)
74  _condition.wait(lock);
75 
76  lock.unlock();
77 }
size_t pending_requests
Definition: MapUpdater.h:59
std::mutex _lock
Definition: MapUpdater.h:57
std::condition_variable _condition
Definition: MapUpdater.h:58

+ Here is the caller graph for this function:

void MapUpdater::WorkerThread ( )
private
103 {
104  while (1)
105  {
106  MapUpdateRequest* request = nullptr;
107 
108  _queue.WaitAndPop(request);
109 
110  if (_cancelationToken)
111  return;
112 
113  request->call();
114 
115  delete request;
116  }
117 }
void WaitAndPop(T &value)
Definition: ProducerConsumerQueue.h:69
std::atomic< bool > _cancelationToken
Definition: MapUpdater.h:55
Definition: MapUpdater.cpp:25
void call()
Definition: MapUpdater.cpp:40
ProducerConsumerQueue< MapUpdateRequest * > _queue
Definition: MapUpdater.h:52

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Friends And Related Function Documentation

friend class MapUpdateRequest
friend

Member Data Documentation

std::atomic<bool> MapUpdater::_cancelationToken
private
std::condition_variable MapUpdater::_condition
private
std::mutex MapUpdater::_lock
private
ProducerConsumerQueue<MapUpdateRequest*> MapUpdater::_queue
private
std::vector<std::thread> MapUpdater::_workerThreads
private
size_t MapUpdater::pending_requests
private

The documentation for this class was generated from the following files: