Skip to content

Commit a68d2d7

Browse files
author
cyberjunk
committed
clear pending queries&responses on GC
1 parent 20c6536 commit a68d2d7

File tree

1 file changed

+21
-15
lines changed

1 file changed

+21
-15
lines changed

blakserv/astar.c

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -888,19 +888,6 @@ void AStarThreadProc(astar* Astar)
888888
while (astar_command* cmd = Astar->Commands->dequeue())
889889
AStarHandleCommand(Astar, cmd);
890890

891-
// handle all remaining queries
892-
while (astar_query* query = AStarQueries.dequeue())
893-
{
894-
astar_response* response = AStarRunQuery(Astar, query);
895-
896-
if (response)
897-
AStarResponses.enqueue(response);
898-
899-
delete query;
900-
901-
// don't notify mainthread here, on serversave processing would occur after save/next tick
902-
// and therefore too late. if you pause the worker, you must process final queue items yourself
903-
}
904891
Astar->IsPaused = true;
905892
}
906893
}
@@ -1066,6 +1053,7 @@ void AStarInitGC()
10661053
AStar[i].DoPause = true;
10671054

10681055
// wait for workers to get in pause mode
1056+
// they will process all pending commands first
10691057
while (true)
10701058
{
10711059
bool allpaused = true;
@@ -1078,8 +1066,26 @@ void AStarInitGC()
10781066
break;
10791067
}
10801068

1081-
// deliver all final results to their requesters
1082-
while (AStarDeliverNextResponse()) {};
1069+
// clear the query queue, just discard them due to
1070+
// invalid (ids) and monsters get their waiting flag reset on GC
1071+
while (astar_query* query = AStarQueries.dequeue())
1072+
delete query;
1073+
1074+
// clear the response queues, free mem of pathnodes we not gonna use
1075+
while (astar_response* response = AStarResponses.dequeue())
1076+
{
1077+
if (response->responseType() == AStarPathResponse)
1078+
{
1079+
astar_pathresponse* pathresponse = (astar_pathresponse*)response;
1080+
while (!pathresponse->path.empty())
1081+
{
1082+
astar_path_node* node = pathresponse->path.front();
1083+
pathresponse->path.pop_front();
1084+
free(node);
1085+
}
1086+
}
1087+
delete response;
1088+
}
10831089
}
10841090

10851091
void AStarFinishGC()

0 commit comments

Comments
 (0)