@@ -1858,18 +1858,30 @@ static int delta_cacheable(unsigned long src_size, unsigned long trg_size,
1858
1858
1859
1859
#ifndef NO_PTHREADS
1860
1860
1861
+ /* Protect access to object database */
1861
1862
static pthread_mutex_t read_mutex ;
1862
1863
#define read_lock () pthread_mutex_lock(&read_mutex)
1863
1864
#define read_unlock () pthread_mutex_unlock(&read_mutex)
1864
1865
1866
+ /* Protect delta_cache_size */
1865
1867
static pthread_mutex_t cache_mutex ;
1866
1868
#define cache_lock () pthread_mutex_lock(&cache_mutex)
1867
1869
#define cache_unlock () pthread_mutex_unlock(&cache_mutex)
1868
1870
1871
+ /*
1872
+ * Protect object list partitioning (e.g. struct thread_param) and
1873
+ * progress_state
1874
+ */
1869
1875
static pthread_mutex_t progress_mutex ;
1870
1876
#define progress_lock () pthread_mutex_lock(&progress_mutex)
1871
1877
#define progress_unlock () pthread_mutex_unlock(&progress_mutex)
1872
1878
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
+ */
1873
1885
#else
1874
1886
1875
1887
#define read_lock () (void)0
@@ -2251,12 +2263,19 @@ static void try_to_free_from_threads(size_t size)
2251
2263
static try_to_free_t old_try_to_free_routine ;
2252
2264
2253
2265
/*
2266
+ * The main object list is split into smaller lists, each is handed to
2267
+ * one worker.
2268
+ *
2254
2269
* The main thread waits on the condition that (at least) one of the workers
2255
2270
* has stopped working (which is indicated in the .working member of
2256
2271
* struct thread_params).
2272
+ *
2257
2273
* When a work thread has completed its work, it sets .working to 0 and
2258
2274
* signals the main thread and waits on the condition that .data_ready
2259
2275
* 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.
2260
2279
*/
2261
2280
2262
2281
struct thread_params {
0 commit comments