{"thread":{"id":"40531","subject":"thread-utils: build with NO_PTHREADS fails","startedAt":"2015-10-11T12:58:30Z","lastAt":"2015-10-14T11:24:03Z","messageCount":4,"participants":["Victor Leschuk","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"271411","messageId":"6AE1604EE3EC5F4296C096518C6B77EE5D0FDAB9E8@mail.accesssoftek.com","threadId":"40531","inReplyTo":null,"subject":"thread-utils: build with NO_PTHREADS fails","fromName":"Victor Leschuk","fromEmail":"vleschuk@accesssoftek.com","sentAt":"2015-10-11T12:58:30Z","receivedAt":"2015-10-11T12:58:30Z","isPatch":false,"sender":{"key":"vleschuk@accesssoftek.com","avatar":null},"body":"Hello all,\n\nI 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.\n\nIn brief the situation is the following:\n\nin header file we have something like that:\n\n\n#ifndef NO_PTHREAD\nextern int online_cpus(void);\n\n#else\n#define online_cpus() 1\n#endif // NO_PTHREAD\n\nand in *.c file:\n\n\nint online_cpus(void)\n{\n    // ...\n}\n\nSo the compilation fails with: \n\ntest.c:3:21: error: macro \"online_cpus\" passed 1 arguments, but takes just 0\n int online_cpus(void)\n\nThat'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.\n\n\n--\nBest Regards,\nVictor\n\ndiff --git a/thread-utils.c b/thread-utils.c\nindex a2135e0..f3e90fb 100644\n--- a/thread-utils.c\n+++ b/thread-utils.c\n@@ -20,6 +20,7 @@\n \n int online_cpus(void)\n {\n+#ifndef NO_PTHREADS\n #ifdef _SC_NPROCESSORS_ONLN\n \tlong ncpus;\n #endif\n@@ -58,11 +59,13 @@ int online_cpus(void)\n \t\treturn (int)ncpus;\n #endif\n \n+#endif\n \treturn 1;\n }\n \n int init_recursive_mutex(pthread_mutex_t *m)\n {\n+#ifndef NO_PTHREADS\n \tpthread_mutexattr_t a;\n \tint ret;\n \n@@ -74,4 +77,7 @@ int init_recursive_mutex(pthread_mutex_t *m)\n \t\tpthread_mutexattr_destroy(&a);\n \t}\n \treturn ret;\n+#else\n+\treturn 0;\n+#endif\n }\ndiff --git a/thread-utils.h b/thread-utils.h\nindex d9a769d..6fb98c3 100644\n--- a/thread-utils.h\n+++ b/thread-utils.h\n@@ -7,9 +7,5 @@\n extern int online_cpus(void);\n extern int init_recursive_mutex(pthread_mutex_t*);\n \n-#else\n-\n-#define online_cpus() 1\n-\n #endif\n #endif /* THREAD_COMPAT_H */\n"},{"id":"271450","messageId":"xmqq7fmsnkp9.fsf@gitster.mtv.corp.google.com","threadId":"40531","inReplyTo":"6AE1604EE3EC5F4296C096518C6B77EE5D0FDAB9E8@mail.accesssoftek.com","subject":"Re: thread-utils: build with NO_PTHREADS fails","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-10-12T15:57:38Z","receivedAt":"2015-10-12T15:57:38Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Victor Leschuk <vleschuk@accesssoftek.com> writes:\n\n> I think that no one tried it for a long time but I needed a\n> single-threaded git version for debug purpose. I tried to build\n> with -DNO_PTHREADS and thread-utils.c failed to compile.\n>\n> In brief the situation is the following:\n>\n> in header file we have something like that:\n>\n>\n> #ifndef NO_PTHREAD\n> extern int online_cpus(void);\n>\n> #else\n> #define online_cpus() 1\n> #endif // NO_PTHREAD\n>\n> and in *.c file:\n>\n>\n> int online_cpus(void)\n> {\n>     // ...\n> }\n\nYeah, that is obviously incorrect.\n\nThe whole implementation of thread-utils.c should be enabled only\nunder ifndef NO_PTHREADS and thread-utils.h should also privide a\nno-op macro for init_recursive_mutex() just like it already does for\nonline_cpus(), which would make it unnecessary to have ifndef\nNO_PTHREADS sprinkled all over the place inside thread-utils.c, no?\n"},{"id":"271463","messageId":"xmqqd1wkm0om.fsf@gitster.mtv.corp.google.com","threadId":"40531","inReplyTo":"xmqq7fmsnkp9.fsf@gitster.mtv.corp.google.com","subject":"Re: thread-utils: build with NO_PTHREADS fails","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-10-12T17:55:21Z","receivedAt":"2015-10-12T17:55:21Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> Victor Leschuk <vleschuk@accesssoftek.com> writes:\n>\n>> I think that no one tried it for a long time but I needed a\n>> single-threaded git version for debug purpose. I tried to build\n>> with -DNO_PTHREADS and thread-utils.c failed to compile.\n>>\n>> In brief the situation is the following:\n>>\n>> in header file we have something like that:\n>>\n>>\n>> #ifndef NO_PTHREAD\n>> extern int online_cpus(void);\n>>\n>> #else\n>> #define online_cpus() 1\n>> #endif // NO_PTHREAD\n>>\n>> and in *.c file:\n>>\n>>\n>> int online_cpus(void)\n>> {\n>>     // ...\n>> }\n>\n> Yeah, that is obviously incorrect.\n> ...\n\nWell, no, I spoke too early.  I do not see there is much wrong here.\n\nThere is this bit in the Makefile:\n\n        ifdef NO_PTHREADS\n                BASIC_CFLAGS += -DNO_PTHREADS\n        else\n                BASIC_CFLAGS += $(PTHREAD_CFLAGS)\n                EXTLIBS += $(PTHREAD_LIBS)\n                LIB_OBJS += thread-utils.o\n        endif\n\nThe source file thread-utils.c is not compiled to thread-utils.o if\nyou say NO_PTHREADS, and the resulting libgit.a does not of course\nhave it.\n"},{"id":"271640","messageId":"6AE1604EE3EC5F4296C096518C6B77EE5D0FDAB9ED@mail.accesssoftek.com","threadId":"40531","inReplyTo":"xmqqd1wkm0om.fsf@gitster.mtv.corp.google.com","subject":"RE: thread-utils: build with NO_PTHREADS fails","fromName":"Victor Leschuk","fromEmail":"vleschuk@accesssoftek.com","sentAt":"2015-10-14T11:24:03Z","receivedAt":"2015-10-14T11:24:03Z","isPatch":false,"sender":{"key":"vleschuk@accesssoftek.com","avatar":null},"body":"Hello Junio, \n\nsorry that was my fault, I was building it wrong way (defined NO_PTHREADS in CFLAGS variable, not as separate make variable). Sorry for the false alarm.\n\n--\nBest Regards,\nVictor\n________________________________________\nFrom: Junio C Hamano [jch2355@gmail.com] On Behalf Of Junio C Hamano [gitster@pobox.com]\nSent: Monday, October 12, 2015 10:55 AM\nTo: Victor Leschuk\nCc: git@vger.kernel.org; vleschuk@gmail.com\nSubject: Re: thread-utils: build with NO_PTHREADS fails\n\nJunio C Hamano <gitster@pobox.com> writes:\n\n> Victor Leschuk <vleschuk@accesssoftek.com> writes:\n>\n>> I think that no one tried it for a long time but I needed a\n>> single-threaded git version for debug purpose. I tried to build\n>> with -DNO_PTHREADS and thread-utils.c failed to compile.\n>>\n>> In brief the situation is the following:\n>>\n>> in header file we have something like that:\n>>\n>>\n>> #ifndef NO_PTHREAD\n>> extern int online_cpus(void);\n>>\n>> #else\n>> #define online_cpus() 1\n>> #endif // NO_PTHREAD\n>>\n>> and in *.c file:\n>>\n>>\n>> int online_cpus(void)\n>> {\n>>     // ...\n>> }\n>\n> Yeah, that is obviously incorrect.\n> ...\n\nWell, no, I spoke too early.  I do not see there is much wrong here.\n\nThere is this bit in the Makefile:\n\n        ifdef NO_PTHREADS\n                BASIC_CFLAGS += -DNO_PTHREADS\n        else\n                BASIC_CFLAGS += $(PTHREAD_CFLAGS)\n                EXTLIBS += $(PTHREAD_LIBS)\n                LIB_OBJS += thread-utils.o\n        endif\n\nThe source file thread-utils.c is not compiled to thread-utils.o if\nyou say NO_PTHREADS, and the resulting libgit.a does not of course\nhave it.\n"}]}