18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-03 11:15:23 +01:00
Commit Graph

2 Commits

Author SHA1 Message Date
jerrrrycho 4569bff42c refactor: SonarQube findings of the worker pool and the settings pointer
The memory orders of the worker pool and of the settings pointer stay as
they are; each line says why its order is enough. The settings pointer
is set once, so it can't be const. The pool threads are std::jthread,
which the destructor of the pool joins as before. wake() and next_job()
are const, the test lambdas capture what they use, and the length of a
vehicle found near another one comes from a helper, which keeps
update_neighbours() under the cognitive complexity limit.
2026-12-02 14:12:03 +01:00
jerrrrycho 9cc1eb48a4 perf(physics): the worker threads look out for the next job before they sleep, and wake one another
Each job of worker_pool released the semaphore of every thread it wanted from the calling thread, and the threads
slept again right after it. A frame of the test mode runs four or five jobs (the neighbours, the facts, the steps,
the hose exchange), so the main thread made some 40 wake calls a frame: 3.3 % of its time on Tomaszewo, and on
linia 107 it waited 4.8 % of its time for threads woken late.

Now a thread done with a job looks out for the next one for 50 us (spin_time), as the jobs of a frame come close
after one another, and only then sleeps. A job is a ticket (its number and the seats left for the threads of the
pool): the threads looking out take a seat each, and sleeping ones are woken for the seats left, two by the calling
thread and two more by each thread which takes a seat, so the wakes go out as a tree. A thread going to sleep sets
its flag before a last look at the ticket, and a waker takes the flag before it releases, so no job is missed and no
semaphore released twice. The calling thread closes the seats nobody took once it is done, then waits for the
threads which took one, looking out for them for a while before it sleeps on the count.

Which thread does which index never mattered for the results, so they don't change. workerpool.cpp moved into the
core library, for the new unit tests (each index once with any number of threads, jobs back to back and after the
threads slept, the threads of the pool taking part, an exception passed on).
2026-12-02 06:15:59 +01:00