https://github.com/git/git
Revision 5843080c85ae9d13f77442bec7bbec8e84a18100 authored by Junio C Hamano on 02 March 2023, 16:44:16 UTC, committed by Johannes Schindelin on 22 March 2023, 16:58:29 UTC
In http.c, the run_active_slot() function allows the given "slot" to
make progress by calling step_active_slots() in a loop repeatedly,
and the loop is not left until the request held in the slot
completes.

Ages ago, we used to use the slot->in_use member to get out of the
loop, which misbehaved when the request in "slot" completes (at
which time, the result of the request is copied away from the slot,
and the in_use member is cleared, making the slot ready to be
reused), and the "slot" gets reused to service a different request
(at which time, the "slot" becomes in_use again, even though it is
for a different request).  The loop terminating condition mistakenly
thought that the original request has yet to be completed.

Today's code, after baa7b67d (HTTP slot reuse fixes, 2006-03-10)
fixed this issue, uses a separate "slot->finished" member that is
set in run_active_slot() to point to an on-stack variable, and the
code that completes the request in finish_active_slot() clears the
on-stack variable via the pointer to signal that the particular
request held by the slot has completed.  It also clears the in_use
member (as before that fix), so that the slot itself can safely be
reused for an unrelated request.

One thing that is not quite clean in this arrangement is that,
unless the slot gets reused, at which point the finished member is
reset to NULL, the member keeps the value of &finished, which
becomes a dangling pointer into the stack when run_active_slot()
returns.  Clear the finished member before the control leaves the
function, which has a side effect of unconfusing compilers like
recent GCC 12 that is over-eager to warn against such an assignment.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 321854a
Raw File
Tip revision: 5843080c85ae9d13f77442bec7bbec8e84a18100 authored by Junio C Hamano on 02 March 2023, 16:44:16 UTC
http.c: clear the 'finished' member once we are done with it
Tip revision: 5843080
thread-utils.h
#ifndef THREAD_COMPAT_H
#define THREAD_COMPAT_H

#ifndef NO_PTHREADS
#include <pthread.h>

#define HAVE_THREADS 1

#else

#define HAVE_THREADS 0

/*
 * macros instead of typedefs because pthread definitions may have
 * been pulled in by some system dependencies even though the user
 * wants to disable pthread.
 */
#define pthread_t int
#define pthread_mutex_t int
#define pthread_cond_t int
#define pthread_key_t int

#define pthread_mutex_init(mutex, attr) dummy_pthread_init(mutex)
#define pthread_mutex_lock(mutex)
#define pthread_mutex_unlock(mutex)
#define pthread_mutex_destroy(mutex)

#define pthread_cond_init(cond, attr) dummy_pthread_init(cond)
#define pthread_cond_wait(cond, mutex)
#define pthread_cond_signal(cond)
#define pthread_cond_broadcast(cond)
#define pthread_cond_destroy(cond)

#define pthread_key_create(key, attr) dummy_pthread_init(key)
#define pthread_key_delete(key)

#define pthread_create(thread, attr, fn, data) \
	dummy_pthread_create(thread, attr, fn, data)
#define pthread_join(thread, retval) \
	dummy_pthread_join(thread, retval)

#define pthread_setspecific(key, data)
#define pthread_getspecific(key) NULL

int dummy_pthread_create(pthread_t *pthread, const void *attr,
			 void *(*fn)(void *), void *data);
int dummy_pthread_join(pthread_t pthread, void **retval);

int dummy_pthread_init(void *);

#endif

int online_cpus(void);
int init_recursive_mutex(pthread_mutex_t*);


#endif /* THREAD_COMPAT_H */
back to top