git/list[1] front-page[2] threads[3] people[4] search[5] about
 

thread-utils: build with NO_PTHREADS fails

From
VLVictor Leschuk <vleschuk@accesssoftek.com>
Date
Oct 11, 2015, 12:58 UTC
Message-ID
<6AE1604EE3EC5F4296C096518C6B77EE5D0FDAB9E8@mail.accesssoftek.com>
Hello all,
I think that no one tried it for a long time but I needed a single-threaded git version for debug purpose. I tried to build with -DNO_PTHREADS and thread-utils.c failed to compile.
In brief the situation is the following:
in header file we have something like that:

#ifndef NO_PTHREAD extern int online_cpus(void);

#else #define online_cpus() 1 #endif // NO_PTHREAD

and in *.c file:
int online_cpus(void)
{
    // ...
}
So the compilation fails with: 
test.c:3:21: error: macro "online_cpus" passed 1 arguments, but takes just 0
 int online_cpus(void)
That's a tiny issue, but maybe we could apply a straight-forward solution (see attached diff)? If you agree I'll prepare a properly-formatted [PATCH] submit.

-- Best Regards, Victor

diff --git a/thread-utils.c b/thread-utils.c
index a2135e0..f3e90fb 100644
--- a/thread-utils.c
+++ b/thread-utils.c
@@ -20,6 +20,7 @@
 
 int online_cpus(void)
 {
+#ifndef NO_PTHREADS
 #ifdef _SC_NPROCESSORS_ONLN
 	long ncpus;
 #endif
@@ -58,11 +59,13 @@ int online_cpus(void)
 		return (int)ncpus;
 #endif
 
+#endif
 	return 1;
 }
 
 int init_recursive_mutex(pthread_mutex_t *m)
 {
+#ifndef NO_PTHREADS
 	pthread_mutexattr_t a;
 	int ret;
 
@@ -74,4 +77,7 @@ int init_recursive_mutex(pthread_mutex_t *m)
 		pthread_mutexattr_destroy(&a);
 	}
 	return ret;
+#else
+	return 0;
+#endif
 }
diff --git a/thread-utils.h b/thread-utils.h
index d9a769d..6fb98c3 100644
--- a/thread-utils.h
+++ b/thread-utils.h
@@ -7,9 +7,5 @@
 extern int online_cpus(void);
 extern int init_recursive_mutex(pthread_mutex_t*);
 
-#else
-
-#define online_cpus() 1
-
 #endif
 #endif /* THREAD_COMPAT_H */
Next: Junio C Hamano
Message 1 of 4 in “thread-utils: build with NO_PTHREADS fails”
  1. Victor LeschukOct 11, 2015
  2. Junio C HamanoOct 12, 2015
  3. Junio C HamanoOct 12, 2015
  4. Victor LeschukOct 14, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.