odb.c
14.1 KB
-
Refactor pack memory management and locking to be safer · 098ac57a
Using an atomic reference counter is difficult to make cross-platform, as the reference count implementations are generally processor specific. Its also hard to do a proper multi-read/single-write implementation. We now use a simple mutex around the reference count for the list of packs. Readers grab the mutex and either build the list, or increment the existing one's reference count. When the reader is done with the list, the reference count is decremented. In this way parallel readers are able to operate on the list without worrying about it being deallocated out from under them. Individual pack structures are held by reference counts, but we only care about the list the pack structure is held in. There is no need to increment/decrement the pack reference counts as we scan through them during a read operation, the caller holds the git_packlist and that is sufficient to hold the packs it references. Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Shawn O. Pearce committed