|
KiCad PCB EDA Suite
|
Registry of background git cleanup threads that outlive the owning project or dialog. More...
#include <kigit_orphan_registry.h>
Classes | |
| struct | ENTRY |
| struct | SHARED_STATE |
Public Member Functions | |
| KIGIT_ORPHAN_REGISTRY () | |
| ~KIGIT_ORPHAN_REGISTRY () | |
| KIGIT_ORPHAN_REGISTRY (const KIGIT_ORPHAN_REGISTRY &)=delete | |
| KIGIT_ORPHAN_REGISTRY & | operator= (const KIGIT_ORPHAN_REGISTRY &)=delete |
| template<typename F> | |
| bool | Register (const std::string &aLabel, F &&aWork) |
| Spawn a tracked orphan thread running aWork. | |
| size_t | TrackedCount () const |
| Return the number of tracked orphan threads that have not yet finished executing. | |
| size_t | JoinAll (std::chrono::milliseconds aTimeout) |
| Join all registered orphan threads, giving them up to aTimeout to finish cooperatively. | |
Private Member Functions | |
| void | reapLocked () |
Private Attributes | |
| std::mutex | m_mutex |
| std::vector< ENTRY > | m_entries |
| bool | m_shuttingDown = false |
Registry of background git cleanup threads that outlive the owning project or dialog.
When a user abandons a slow git close (for example, a fetch stuck under a blocking recv) we cannot wait for the libgit2 worker to notice cancellation before the UI returns, but we also cannot call git_libgit2_shutdown() while that worker is still inside libgit2. The registry lets us track such "orphan" threads and join them with a bounded timeout during application shutdown.
Each entry is reference-counted via std::shared_ptr so that a detached worker never touches freed registry state after the registry has given up on it: the worker and the registry each hold their own shared reference to a small state block.
Definition at line 59 of file kigit_orphan_registry.h.
|
default |
References KIGIT_ORPHAN_REGISTRY().
Referenced by KIGIT_ORPHAN_REGISTRY(), KIGIT_ORPHAN_REGISTRY(), and operator=().
| KIGIT_ORPHAN_REGISTRY::~KIGIT_ORPHAN_REGISTRY | ( | ) |
Definition at line 30 of file kigit_orphan_registry.cpp.
|
delete |
References KIGIT_ORPHAN_REGISTRY().
| size_t KIGIT_ORPHAN_REGISTRY::JoinAll | ( | std::chrono::milliseconds | aTimeout | ) |
Join all registered orphan threads, giving them up to aTimeout to finish cooperatively.
After the timeout the remaining threads are detached so the caller can proceed with teardown; the shared per-entry state outlives the registry until the worker itself drops its reference, so detached workers are safe to keep running.
Once JoinAll() has been called the registry enters a shutting-down state and Register() returns false; this prevents a late caller from queueing a new orphan after the join window has already closed.
Definition at line 65 of file kigit_orphan_registry.cpp.
References m_entries, m_mutex, m_shuttingDown, and traceGit.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().
|
delete |
References KIGIT_ORPHAN_REGISTRY().
|
private |
Definition at line 119 of file kigit_orphan_registry.cpp.
References m_entries.
Referenced by Register().
|
inline |
Spawn a tracked orphan thread running aWork.
The thread is owned by the registry and will be joined during JoinAll() or on destruction.
The callable is accepted by forwarding reference so move-only work objects (for example lambdas capturing a std::unique_ptr) are supported without forcing shared ownership on the caller.
If the registry has already begun shutdown via JoinAll() the call returns false and aWork is not invoked; the caller is expected to run the cleanup synchronously or drop it.
| aLabel | Human-readable tag used in trace logs, e.g. "abandon close /home/user/proj.kicad_pro". |
| aWork | Work function executed on the new thread. It should honour any cooperative cancellation flag supplied by the caller before performing blocking libgit2 calls. |
Definition at line 90 of file kigit_orphan_registry.h.
References F, KIGIT_ORPHAN_REGISTRY::ENTRY::m_created, m_entries, KIGIT_ORPHAN_REGISTRY::ENTRY::m_label, m_mutex, m_shuttingDown, KIGIT_ORPHAN_REGISTRY::ENTRY::m_state, KIGIT_ORPHAN_REGISTRY::ENTRY::m_thread, reapLocked(), and traceGit.
Referenced by BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), BOOST_AUTO_TEST_CASE(), and PROJECT_TREE_PANE::EmptyTreePrj().
| size_t KIGIT_ORPHAN_REGISTRY::TrackedCount | ( | ) | const |
Return the number of tracked orphan threads that have not yet finished executing.
Threads that JoinAll() detached after a timeout are no longer tracked and do not contribute to this count.
Definition at line 50 of file kigit_orphan_registry.cpp.
References m_entries, and m_mutex.
Referenced by BOOST_AUTO_TEST_CASE(), and BOOST_AUTO_TEST_CASE().
|
private |
Definition at line 190 of file kigit_orphan_registry.h.
Referenced by JoinAll(), reapLocked(), Register(), TrackedCount(), and ~KIGIT_ORPHAN_REGISTRY().
|
mutableprivate |
Definition at line 189 of file kigit_orphan_registry.h.
Referenced by JoinAll(), Register(), TrackedCount(), and ~KIGIT_ORPHAN_REGISTRY().
|
private |
Definition at line 191 of file kigit_orphan_registry.h.
Referenced by JoinAll(), and Register().