Merge branch 'master' into Playerbot
This commit is contained in:
@@ -3516,20 +3516,20 @@ void ObjectMgr::LoadVehicleSeatAddon()
|
||||
|
||||
if (!sVehicleSeatStore.LookupEntry(seatID))
|
||||
{
|
||||
LOG_ERROR("sql.sql", "Table `vehicle_seat_addon`: SeatID: %u does not exist in VehicleSeat.dbc. Skipping entry.", seatID);
|
||||
LOG_ERROR("sql.sql", "Table `vehicle_seat_addon`: SeatID: {} does not exist in VehicleSeat.dbc. Skipping entry.", seatID);
|
||||
continue;
|
||||
}
|
||||
|
||||
// Sanitizing values
|
||||
if (orientation > float(M_PI * 2))
|
||||
{
|
||||
LOG_ERROR("sql.sql", "Table `vehicle_seat_addon`: SeatID: %u is using invalid angle offset value (%f). Set Value to 0.", seatID, orientation);
|
||||
LOG_ERROR("sql.sql", "Table `vehicle_seat_addon`: SeatID: {} is using invalid angle offset value ({}). Set Value to 0.", seatID, orientation);
|
||||
orientation = 0.0f;
|
||||
}
|
||||
|
||||
if (exitParam >= AsUnderlyingType(VehicleExitParameters::VehicleExitParamMax))
|
||||
{
|
||||
LOG_ERROR("sql.sql", "Table `vehicle_seat_addon`: SeatID: %u is using invalid exit parameter value (%u). Setting to 0 (none).", seatID, exitParam);
|
||||
LOG_ERROR("sql.sql", "Table `vehicle_seat_addon`: SeatID: {} is using invalid exit parameter value ({}). Setting to 0 (none).", seatID, exitParam);
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -3538,7 +3538,7 @@ void ObjectMgr::LoadVehicleSeatAddon()
|
||||
++count;
|
||||
} while (result->NextRow());
|
||||
|
||||
LOG_INFO("server.loading", ">> Loaded %u Vehicle Seat Addon entries in %u ms", count, GetMSTimeDiffToNow(oldMSTime));
|
||||
LOG_INFO("server.loading", ">> Loaded {} Vehicle Seat Addon entries in {} ms", count, GetMSTimeDiffToNow(oldMSTime));
|
||||
}
|
||||
|
||||
void ObjectMgr::LoadPetLevelInfo()
|
||||
|
||||
@@ -67,7 +67,7 @@ private:
|
||||
uint32 m_diff;
|
||||
};
|
||||
|
||||
MapUpdater::MapUpdater(): pending_requests(0)
|
||||
MapUpdater::MapUpdater() : pending_requests(0), _cancelationToken(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -84,10 +84,11 @@ void MapUpdater::deactivate()
|
||||
{
|
||||
_cancelationToken = true;
|
||||
|
||||
wait();
|
||||
wait(); // This is where we wait for tasks to complete
|
||||
|
||||
_queue.Cancel();
|
||||
_queue.Cancel(); // Cancel the queue to prevent further task processing
|
||||
|
||||
// Join all worker threads
|
||||
for (auto& thread : _workerThreads)
|
||||
{
|
||||
if (thread.joinable())
|
||||
@@ -99,44 +100,45 @@ void MapUpdater::deactivate()
|
||||
|
||||
void MapUpdater::wait()
|
||||
{
|
||||
std::unique_lock<std::mutex> guard(_lock);
|
||||
std::unique_lock<std::mutex> guard(_lock); // Guard lock for safe waiting
|
||||
|
||||
while (pending_requests > 0)
|
||||
_condition.wait(guard);
|
||||
// Wait until there are no pending requests
|
||||
_condition.wait(guard, [this] {
|
||||
return pending_requests.load(std::memory_order_acquire) == 0;
|
||||
});
|
||||
}
|
||||
|
||||
guard.unlock();
|
||||
void MapUpdater::schedule_task(UpdateRequest* request)
|
||||
{
|
||||
// Atomic increment for pending_requests
|
||||
pending_requests.fetch_add(1, std::memory_order_release);
|
||||
_queue.Push(request);
|
||||
}
|
||||
|
||||
void MapUpdater::schedule_update(Map& map, uint32 diff, uint32 s_diff)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(_lock);
|
||||
|
||||
++pending_requests;
|
||||
|
||||
_queue.Push(new MapUpdateRequest(map, *this, diff, s_diff));
|
||||
schedule_task(new MapUpdateRequest(map, *this, diff, s_diff));
|
||||
}
|
||||
|
||||
void MapUpdater::schedule_lfg_update(uint32 diff)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(_lock);
|
||||
|
||||
++pending_requests;
|
||||
|
||||
_queue.Push(new LFGUpdateRequest(*this, diff));
|
||||
schedule_task(new LFGUpdateRequest(*this, diff));
|
||||
}
|
||||
|
||||
bool MapUpdater::activated()
|
||||
{
|
||||
return _workerThreads.size() > 0;
|
||||
return !_workerThreads.empty();
|
||||
}
|
||||
|
||||
void MapUpdater::update_finished()
|
||||
{
|
||||
std::lock_guard<std::mutex> lock(_lock);
|
||||
|
||||
--pending_requests;
|
||||
|
||||
_condition.notify_all();
|
||||
// Atomic decrement for pending_requests
|
||||
if (pending_requests.fetch_sub(1, std::memory_order_acquire) == 1)
|
||||
{
|
||||
// Only notify when pending_requests becomes 0 (i.e., all tasks are finished)
|
||||
std::lock_guard<std::mutex> lock(_lock); // Lock only for condition variable notification
|
||||
_condition.notify_all(); // Notify waiting threads that all requests are complete
|
||||
}
|
||||
}
|
||||
|
||||
void MapUpdater::WorkerThread()
|
||||
@@ -145,16 +147,16 @@ void MapUpdater::WorkerThread()
|
||||
CharacterDatabase.WarnAboutSyncQueries(true);
|
||||
WorldDatabase.WarnAboutSyncQueries(true);
|
||||
|
||||
while (1)
|
||||
while (!_cancelationToken)
|
||||
{
|
||||
UpdateRequest* request = nullptr;
|
||||
|
||||
_queue.WaitAndPop(request);
|
||||
if (_cancelationToken)
|
||||
return;
|
||||
_queue.WaitAndPop(request); // Wait for and pop a request from the queue
|
||||
|
||||
request->call();
|
||||
|
||||
delete request;
|
||||
if (!_cancelationToken && request)
|
||||
{
|
||||
request->call(); // Execute the request
|
||||
delete request; // Clean up after processing
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "PCQueue.h"
|
||||
#include <condition_variable>
|
||||
#include <thread>
|
||||
#include <atomic>
|
||||
|
||||
class Map;
|
||||
class UpdateRequest;
|
||||
@@ -32,6 +33,7 @@ public:
|
||||
MapUpdater();
|
||||
~MapUpdater() = default;
|
||||
|
||||
void schedule_task(UpdateRequest* request);
|
||||
void schedule_update(Map& map, uint32 diff, uint32 s_diff);
|
||||
void schedule_lfg_update(uint32 diff);
|
||||
void wait();
|
||||
@@ -42,15 +44,12 @@ public:
|
||||
|
||||
private:
|
||||
void WorkerThread();
|
||||
|
||||
ProducerConsumerQueue<UpdateRequest*> _queue;
|
||||
|
||||
std::atomic<int> pending_requests; // Use std::atomic for pending_requests to avoid lock contention
|
||||
std::atomic<bool> _cancelationToken; // Atomic flag for cancellation to avoid race conditions
|
||||
std::vector<std::thread> _workerThreads;
|
||||
std::atomic<bool> _cancelationToken;
|
||||
|
||||
std::mutex _lock;
|
||||
std::mutex _lock; // Mutex and condition variable for synchronization
|
||||
std::condition_variable _condition;
|
||||
std::size_t pending_requests;
|
||||
};
|
||||
|
||||
#endif //_MAP_UPDATER_H_INCLUDED
|
||||
|
||||
@@ -139,7 +139,7 @@ void MotdMgr::LoadLocalizedMotds(uint32 realmId) {
|
||||
|
||||
if (!baseResult)
|
||||
{
|
||||
LOG_ERROR("server.loading", "No base MOTD found for realm %u. Localized MOTDs will not be loaded.", realmId);
|
||||
LOG_ERROR("server.loading", "No base MOTD found for realm {}. Localized MOTDs will not be loaded.", realmId);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user