TrinityCore
Loading...
Searching...
No Matches
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"
23#include <condition_variable>
24#include <mutex>
25#include <thread>
26#include <vector>
27
29class Map;
30
32{
33 public:
34
35 MapUpdater() : _cancelationToken(false), pending_requests(0) {}
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() const;
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
#define TC_GAME_API
Definition Define.h:129
uint32_t uint32
Definition Define.h:154
std::vector< std::thread > _workerThreads
Definition MapUpdater.h:54
std::mutex _lock
Definition MapUpdater.h:57
size_t pending_requests
Definition MapUpdater.h:59
std::atomic< bool > _cancelationToken
Definition MapUpdater.h:55
ProducerConsumerQueue< MapUpdateRequest * > _queue
Definition MapUpdater.h:52
std::condition_variable _condition
Definition MapUpdater.h:58
Definition Map.h:225