Git fork

Revert barrier-based LSan threading race workaround

The extra "barrier" approach was too much code whose sole purpose
was to work around a race that is not even ours (i.e. in LSan's
teardown code).

In preparation for queuing a solution taking a much-less-invasive
approach, let's revert them.

-39
-7
Makefile
··· 141 141 # 142 142 # Define NO_PTHREADS if you do not have or do not want to use Pthreads. 143 143 # 144 - # Define THREAD_BARRIER_PTHREAD if your system has pthread_barrier_t. Barrier 145 - # support is optional and is only helpful when building with SANITIZE=leak, as 146 - # it is used to eliminate some races in the leak-checker. 147 - # 148 144 # Define NO_PREAD if you have a problem with pread() system call (e.g. 149 145 # cygwin1.dll before v1.5.22). 150 146 # ··· 2083 2079 else 2084 2080 BASIC_CFLAGS += $(PTHREAD_CFLAGS) 2085 2081 EXTLIBS += $(PTHREAD_LIBS) 2086 - ifdef THREAD_BARRIER_PTHREAD 2087 - BASIC_CFLAGS += -DTHREAD_BARRIER_PTHREAD 2088 - endif 2089 2082 endif 2090 2083 2091 2084 ifdef HAVE_PATHS_H
-8
builtin/grep.c
··· 101 101 /* Signalled when we are finished with everything. */ 102 102 static pthread_cond_t cond_result; 103 103 104 - /* Synchronize the start of all threads */ 105 - static maybe_thread_barrier_t start_barrier; 106 - 107 104 static int skip_first_line; 108 105 109 106 static void add_work(struct grep_opt *opt, struct grep_source *gs) ··· 201 198 int hit = 0; 202 199 struct grep_opt *opt = arg; 203 200 204 - maybe_thread_barrier_wait(&start_barrier); 205 - 206 201 while (1) { 207 202 struct work_item *w = get_work(); 208 203 if (!w) ··· 234 229 pthread_cond_init(&cond_add, NULL); 235 230 pthread_cond_init(&cond_write, NULL); 236 231 pthread_cond_init(&cond_result, NULL); 237 - maybe_thread_barrier_init(&start_barrier, NULL, num_threads + 1); 238 232 grep_use_locks = 1; 239 233 enable_obj_read_lock(); 240 234 ··· 254 248 die(_("grep: failed to create thread: %s"), 255 249 strerror(err)); 256 250 } 257 - maybe_thread_barrier_wait(&start_barrier); 258 251 } 259 252 260 253 static int wait_all(void) ··· 291 284 pthread_cond_destroy(&cond_add); 292 285 pthread_cond_destroy(&cond_write); 293 286 pthread_cond_destroy(&cond_result); 294 - maybe_thread_barrier_destroy(&start_barrier); 295 287 grep_use_locks = 0; 296 288 disable_obj_read_lock(); 297 289
-6
builtin/index-pack.c
··· 185 185 186 186 static pthread_key_t key; 187 187 188 - static maybe_thread_barrier_t start_barrier; 189 - 190 188 static inline void lock_mutex(pthread_mutex_t *mutex) 191 189 { 192 190 if (threads_active) ··· 211 209 if (show_stat) 212 210 pthread_mutex_init(&deepest_delta_mutex, NULL); 213 211 pthread_key_create(&key, NULL); 214 - maybe_thread_barrier_init(&start_barrier, NULL, nr_threads); 215 212 CALLOC_ARRAY(thread_data, nr_threads); 216 213 for (i = 0; i < nr_threads; i++) { 217 214 thread_data[i].pack_fd = xopen(curr_pack, O_RDONLY); ··· 234 231 for (i = 0; i < nr_threads; i++) 235 232 close(thread_data[i].pack_fd); 236 233 pthread_key_delete(key); 237 - maybe_thread_barrier_destroy(&start_barrier); 238 234 free(thread_data); 239 235 } 240 236 ··· 1104 1100 1105 1101 static void *threaded_second_pass(void *data) 1106 1102 { 1107 - if (threads_active) 1108 - maybe_thread_barrier_wait(&start_barrier); 1109 1103 if (data) 1110 1104 set_thread_data(data); 1111 1105 for (;;) {
-1
ci/lib.sh
··· 385 385 ;; 386 386 linux-leaks|linux-reftable-leaks) 387 387 export SANITIZE=leak 388 - export THREAD_BARRIER_PTHREAD=1 389 388 ;; 390 389 linux-asan-ubsan) 391 390 export SANITIZE=address,undefined
-17
thread-utils.h
··· 53 53 int online_cpus(void); 54 54 int init_recursive_mutex(pthread_mutex_t*); 55 55 56 - #ifdef THREAD_BARRIER_PTHREAD 57 - #define maybe_thread_barrier_t pthread_barrier_t 58 - #define maybe_thread_barrier_init pthread_barrier_init 59 - #define maybe_thread_barrier_wait pthread_barrier_wait 60 - #define maybe_thread_barrier_destroy pthread_barrier_destroy 61 - #else 62 - #define maybe_thread_barrier_t int 63 - static inline int maybe_thread_barrier_init(maybe_thread_barrier_t *b UNUSED, 64 - void *attr UNUSED, 65 - unsigned nr UNUSED) 66 - { 67 - errno = ENOSYS; 68 - return -1; 69 - } 70 - #define maybe_thread_barrier_wait(barrier) 71 - #define maybe_thread_barrier_destroy(barrier) 72 - #endif 73 56 74 57 #endif /* THREAD_COMPAT_H */