TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MapUpdater.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2008-2016 TrinityCore <http://www.trinitycore.org/>
3  * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published by the
7  * Free Software Foundation; either version 2 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #ifndef _MAP_UPDATER_H_INCLUDED
20 #define _MAP_UPDATER_H_INCLUDED
21 
22 #include "Define.h"
23 #include <mutex>
24 #include <thread>
25 #include <condition_variable>
26 #include "ProducerConsumerQueue.h"
27 
28 class MapUpdateRequest;
29 class Map;
30 
32 {
33  public:
34 
35  MapUpdater() : _cancelationToken(false), pending_requests(0) {}
36  ~MapUpdater() { };
37 
38  friend class MapUpdateRequest;
39 
40  void schedule_update(Map& map, uint32 diff);
41 
42  void wait();
43 
44  void activate(size_t num_threads);
45 
46  void deactivate();
47 
48  bool activated();
49 
50  private:
51 
53 
54  std::vector<std::thread> _workerThreads;
55  std::atomic<bool> _cancelationToken;
56 
57  std::mutex _lock;
58  std::condition_variable _condition;
60 
61  void update_finished();
62 
63  void WorkerThread();
64 };
65 
66 #endif //_MAP_UPDATER_H_INCLUDED
size_t pending_requests
Definition: MapUpdater.h:59
#define false
Definition: CascPort.h:18
std::vector< std::thread > _workerThreads
Definition: MapUpdater.h:54
MapUpdater()
Definition: MapUpdater.h:35
~MapUpdater()
Definition: MapUpdater.h:36
std::mutex _lock
Definition: MapUpdater.h:57
std::atomic< bool > _cancelationToken
Definition: MapUpdater.h:55
uint32_t uint32
Definition: Define.h:150
std::condition_variable _condition
Definition: MapUpdater.h:58
Definition: Map.h:259
Definition: MapUpdater.h:31
Definition: MapUpdater.cpp:25
#define TC_GAME_API
Definition: Define.h:134
ProducerConsumerQueue< MapUpdateRequest * > _queue
Definition: MapUpdater.h:52