Jonathan Nieder [off-list ref] writes:
Since the transport-helper does not use recursive mutexes or ask the
number of cores, it does not require any declarations from the
thread-utils lib. Removing the unnecessary #include avoids false
positives from "make CHECK_HEADER_DEPENDENCIES=1".
Sorry, I was slow and took me some time to realize what is going on.
Isn't it more like "Makefile does not say transport-helper.o depends on
thread-utils.h, but transport-helper.c does include it"? IOW, it not a
false positive; perhaps a real but an unnecessary positive.
The #include directive in question was added in 7851b1e60
(remote-fd/ext: finishing touches after code review, 2010-11-17),
at the same times as the necessary #include for <pthread.h>.
I think the whole four-line block was cut & paste from other places that
use the threading, namely grep.c and pack-objects.c.
I wonder if it is better to do something like this instead. This way, we
can later add more things that threaded part of the system would need to
thread-utils.h inside "ifndef NO_PTHREADS" and they will automatically get
included by all the threaders.
builtin/grep.c | 4 ----
builtin/pack-objects.c | 4 ----
thread-utils.h | 4 ++++
transport-helper.c | 4 ----
4 files changed, 4 insertions(+), 12 deletions(-)
diff --git a/builtin/grep.c b/builtin/grep.c
index adb5424..fdf7131 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -17,11 +17,7 @@
#include "grep.h"
#include "quote.h"
#include "dir.h"
-
-#ifndef NO_PTHREADS
-#include <pthread.h>
#include "thread-utils.h"
-#endif
static char const * const grep_usage[] = {
"git grep [options] [-e] <pattern> [<rev>...] [[--] <path>...]",diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index f027b3a..b0503b2 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -16,11 +16,7 @@
#include "list-objects.h"
#include "progress.h"
#include "refs.h"
-
-#ifndef NO_PTHREADS
-#include <pthread.h>
#include "thread-utils.h"
-#endif
static const char pack_usage[] =
"git pack-objects [ -q | --progress | --all-progress ]\n"
diff --git a/thread-utils.h b/thread-utils.h
index 1727a03..6fb98c3 100644
--- a/thread-utils.h
+++ b/thread-utils.h
@@ -1,7 +1,11 @@
#ifndef THREAD_COMPAT_H
#define THREAD_COMPAT_H
+#ifndef NO_PTHREADS
+#include <pthread.h>
+
extern int online_cpus(void);
extern int init_recursive_mutex(pthread_mutex_t*);
+#endif
#endif /* THREAD_COMPAT_H */
diff --git a/transport-helper.c b/transport-helper.c
index 3a50856..4e4754c 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -8,11 +8,7 @@
#include "quote.h"
#include "remote.h"
#include "string-list.h"
-
-#ifndef NO_PTHREADS
-#include <pthread.h>
#include "thread-utils.h"
-#endif
static int debug;
Junio C Hamano wrote:
I wonder if it is better to do something like this instead.
Yes, I think so. How about this?
Jonathan Nieder (1):
Makefile: transport-helper uses thread-utils.h
Junio C Hamano (1):
simplify inclusion of pthread.h
Makefile | 3 +--
builtin/grep.c | 4 ----
builtin/pack-objects.c | 4 ----
thread-utils.h | 4 ++++
transport-helper.c | 4 ----
5 files changed, 5 insertions(+), 14 deletions(-)
--
1.7.2.4
In v1.7.1.1~56^2 (Thread-safe xmalloc and xrealloc needs a recursive
mutex, 2010-04-08), the thread-utils header started using
pthread_mutex_t, so callers, which generally had been using
#ifndef NO_PTHREADS
#include "thread-utils.h"
#include <pthread.h>
#endif
before, were changed to include <pthread.h> first. It is simpler to
let thread-utils.h take care of the whole matter. This way, we can
later add more things that the threaded part of the system would need
to thread-utils.h inside "ifndef NO_PTHREADS" and they will
automatically get included by all headers.
Signed-off-by: Jonathan Nieder <redacted>
---
builtin/grep.c | 4 ----
builtin/pack-objects.c | 4 ----
thread-utils.h | 4 ++++
transport-helper.c | 4 ----
4 files changed, 4 insertions(+), 12 deletions(-)
diff --git a/builtin/grep.c b/builtin/grep.c
index adb5424..fdf7131 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -17,11 +17,7 @@
#include "grep.h"
#include "quote.h"
#include "dir.h"
-
-#ifndef NO_PTHREADS
-#include <pthread.h>
#include "thread-utils.h"
-#endif
static char const * const grep_usage[] = {
"git grep [options] [-e] <pattern> [<rev>...] [[--] <path>...]",diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index f027b3a..b0503b2 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -16,11 +16,7 @@
#include "list-objects.h"
#include "progress.h"
#include "refs.h"
-
-#ifndef NO_PTHREADS
-#include <pthread.h>
#include "thread-utils.h"
-#endif
static const char pack_usage[] =
"git pack-objects [ -q | --progress | --all-progress ]\n"
diff --git a/thread-utils.h b/thread-utils.h
index 1727a03..6fb98c3 100644
--- a/thread-utils.h
+++ b/thread-utils.h
@@ -1,7 +1,11 @@
#ifndef THREAD_COMPAT_H
#define THREAD_COMPAT_H
+#ifndef NO_PTHREADS
+#include <pthread.h>
+
extern int online_cpus(void);
extern int init_recursive_mutex(pthread_mutex_t*);
+#endif
#endif /* THREAD_COMPAT_H */
diff --git a/transport-helper.c b/transport-helper.c
index 3a50856..4e4754c 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -8,11 +8,7 @@
#include "quote.h"
#include "remote.h"
#include "string-list.h"
-
-#ifndef NO_PTHREADS
-#include <pthread.h>
#include "thread-utils.h"
-#endif
static int debug;
--
1.7.2.4
transport-helper.o gained a dependency on thread-utils.h in
7851b1e (remote-fd/ext: finishing touches after code review,
2010-11-17).
Signed-off-by: Jonathan Nieder <redacted>
---
Makefile | 3 +--
1 files changed, 1 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
index 1fe1a3b..41ab490 100644
--- a/Makefile
+++ b/Makefile
@@ -1937,13 +1937,12 @@ builtin/branch.o builtin/checkout.o builtin/clone.o builtin/reset.o branch.o tra
builtin/bundle.o bundle.o transport.o: bundle.h
builtin/bisect--helper.o builtin/rev-list.o bisect.o: bisect.h
builtin/clone.o builtin/fetch-pack.o transport.o: fetch-pack.h
-builtin/grep.o: thread-utils.h
+builtin/grep.o builtin/pack-objects.o transport-helper.o: thread-utils.h
builtin/send-pack.o transport.o: send-pack.h
builtin/log.o builtin/shortlog.o: shortlog.h
builtin/prune.o builtin/reflog.o reachable.o: reachable.h
builtin/commit.o builtin/revert.o wt-status.o: wt-status.h
builtin/tar-tree.o archive-tar.o: tar.h
-builtin/pack-objects.o: thread-utils.h
connect.o transport.o http-backend.o: url.h
http-fetch.o http-walker.o remote-curl.o transport.o walker.o: walker.h
http.o http-walker.o http-push.o http-fetch.o remote-curl.o: http.h
--
1.7.2.4