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