Skip to content

Commit 2e2c24f

Browse files
committed
Merge branch 'nd/pack-objects-threading-doc'
Doc fix. * nd/pack-objects-threading-doc: pack-objects: document about thread synchronization
2 parents ab53920 + ffbd51c commit 2e2c24f

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

builtin/pack-objects.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1858,18 +1858,30 @@ static int delta_cacheable(unsigned long src_size, unsigned long trg_size,
18581858

18591859
#ifndef NO_PTHREADS
18601860

1861+
/* Protect access to object database */
18611862
static pthread_mutex_t read_mutex;
18621863
#define read_lock() pthread_mutex_lock(&read_mutex)
18631864
#define read_unlock() pthread_mutex_unlock(&read_mutex)
18641865

1866+
/* Protect delta_cache_size */
18651867
static pthread_mutex_t cache_mutex;
18661868
#define cache_lock() pthread_mutex_lock(&cache_mutex)
18671869
#define cache_unlock() pthread_mutex_unlock(&cache_mutex)
18681870

1871+
/*
1872+
* Protect object list partitioning (e.g. struct thread_param) and
1873+
* progress_state
1874+
*/
18691875
static pthread_mutex_t progress_mutex;
18701876
#define progress_lock() pthread_mutex_lock(&progress_mutex)
18711877
#define progress_unlock() pthread_mutex_unlock(&progress_mutex)
18721878

1879+
/*
1880+
* Access to struct object_entry is unprotected since each thread owns
1881+
* a portion of the main object list. Just don't access object entries
1882+
* ahead in the list because they can be stolen and would need
1883+
* progress_mutex for protection.
1884+
*/
18731885
#else
18741886

18751887
#define read_lock() (void)0
@@ -2251,12 +2263,19 @@ static void try_to_free_from_threads(size_t size)
22512263
static try_to_free_t old_try_to_free_routine;
22522264

22532265
/*
2266+
* The main object list is split into smaller lists, each is handed to
2267+
* one worker.
2268+
*
22542269
* The main thread waits on the condition that (at least) one of the workers
22552270
* has stopped working (which is indicated in the .working member of
22562271
* struct thread_params).
2272+
*
22572273
* When a work thread has completed its work, it sets .working to 0 and
22582274
* signals the main thread and waits on the condition that .data_ready
22592275
* becomes 1.
2276+
*
2277+
* The main thread steals half of the work from the worker that has
2278+
* most work left to hand it to the idle worker.
22602279
*/
22612280

22622281
struct thread_params {

0 commit comments

Comments
 (0)