threads / patch / 26015

patchtransport-helper: avoid dependency on thread-utils.h

Subject: [PATCH] transport-helper: avoid dependency on thread-utils.h

## tl;dr

6 messages between Dec 10, 2010 and Dec 10, 2010. Diffs are folded; open one to read it.

replies: 5people: 2as markdown or json

Jonathan Nieder· Dec 10, 2010, 11:48 UTC · lore

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".

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
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>.
This patch seems to work for me, but I wouldn't be surprised if
to be missing something.
 transport-helper.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
Show changes to transport-helper.c +0 −1
diff --git a/transport-helper.c b/transport-helper.c
index 3a50856..7c99051 100644
--- a/transport-helper.c
+++ b/transport-helper.c
@@ -11,7 +11,6 @@
 
 #ifndef NO_PTHREADS
 #include <pthread.h>
-#include "thread-utils.h"
 #endif
 
 static int debug;
-- 
1.7.2.4
Junio C Hamano· Dec 10, 2010, 18:21 UTC · re: Jonathan Nieder · lore

Re: [PATCH] transport-helper: avoid dependency on thread-utils.h

Jonathan Nieder <jrnieder@gmail.com> 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(-)
Show changes to 4 files +4 −12

builtin/grep.c, builtin/pack-objects.c, thread-utils.h, transport-helper.c

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;
 
Jonathan Nieder· Dec 10, 2010, 19:46 UTC · re: Junio C Hamano · lore

[PATCH 0/2] Re: transport-helper: avoid dependency on thread-utils.h

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
Jonathan Nieder· Dec 10, 2010, 19:47 UTC · re: Jonathan Nieder · lore

[PATCH 1/2] simplify inclusion of pthread.h

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 <jrnieder@gmail.com>
---
 builtin/grep.c         |    4 ----
 builtin/pack-objects.c |    4 ----
 thread-utils.h         |    4 ++++
 transport-helper.c     |    4 ----
 4 files changed, 4 insertions(+), 12 deletions(-)
Show changes to 4 files +4 −12

builtin/grep.c, builtin/pack-objects.c, thread-utils.h, transport-helper.c

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
Jonathan Nieder· Dec 10, 2010, 19:51 UTC · re: Jonathan Nieder · lore

Re: [PATCH 1/2] simplify inclusion of pthread.h

Jonathan Nieder wrote:
> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
This one is of course
	From: Junio C Hamano <gitster@pobox.com>

Often enough I remind myself to include the pseudo-header but when the rapid cutting-and-pasting time comes it is easy to forget. :/

Jonathan Nieder· Dec 10, 2010, 19:48 UTC · re: Jonathan Nieder · lore

[PATCH 2/2] Makefile: transport-helper uses thread-utils.h

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 <jrnieder@gmail.com>
---
 Makefile |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
Show changes to Makefile +1 −2
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

← back to recent threads