All of lore.kernel.org
 help / color / mirror / Atom feed
* thread-utils: build with NO_PTHREADS fails
@ 2015-10-11 12:58 Victor Leschuk
  2015-10-12 15:57 ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Victor Leschuk @ 2015-10-11 12:58 UTC (permalink / raw)
  To: git; +Cc: vleschuk

[-- Attachment #1: Type: text/plain, Size: 792 bytes --]

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

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: no_pthreads.patch --]
[-- Type: text/x-patch; name="no_pthreads.patch", Size: 879 bytes --]

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 */

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: thread-utils: build with NO_PTHREADS fails
  2015-10-11 12:58 thread-utils: build with NO_PTHREADS fails Victor Leschuk
@ 2015-10-12 15:57 ` Junio C Hamano
  2015-10-12 17:55   ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2015-10-12 15:57 UTC (permalink / raw)
  To: Victor Leschuk; +Cc: git, vleschuk

Victor Leschuk <vleschuk@accesssoftek.com> writes:

> 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)
> {
>     // ...
> }

Yeah, that is obviously incorrect.

The whole implementation of thread-utils.c should be enabled only
under ifndef NO_PTHREADS and thread-utils.h should also privide a
no-op macro for init_recursive_mutex() just like it already does for
online_cpus(), which would make it unnecessary to have ifndef
NO_PTHREADS sprinkled all over the place inside thread-utils.c, no?

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: thread-utils: build with NO_PTHREADS fails
  2015-10-12 15:57 ` Junio C Hamano
@ 2015-10-12 17:55   ` Junio C Hamano
  2015-10-14 11:24     ` Victor Leschuk
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2015-10-12 17:55 UTC (permalink / raw)
  To: Victor Leschuk; +Cc: git, vleschuk

Junio C Hamano <gitster@pobox.com> writes:

> Victor Leschuk <vleschuk@accesssoftek.com> writes:
>
>> 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)
>> {
>>     // ...
>> }
>
> Yeah, that is obviously incorrect.
> ...

Well, no, I spoke too early.  I do not see there is much wrong here.

There is this bit in the Makefile:

        ifdef NO_PTHREADS
                BASIC_CFLAGS += -DNO_PTHREADS
        else
                BASIC_CFLAGS += $(PTHREAD_CFLAGS)
                EXTLIBS += $(PTHREAD_LIBS)
                LIB_OBJS += thread-utils.o
        endif

The source file thread-utils.c is not compiled to thread-utils.o if
you say NO_PTHREADS, and the resulting libgit.a does not of course
have it.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: thread-utils: build with NO_PTHREADS fails
  2015-10-12 17:55   ` Junio C Hamano
@ 2015-10-14 11:24     ` Victor Leschuk
  0 siblings, 0 replies; 4+ messages in thread
From: Victor Leschuk @ 2015-10-14 11:24 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git, vleschuk

Hello Junio, 

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

--
Best Regards,
Victor
________________________________________
From: Junio C Hamano [jch2355@gmail.com] On Behalf Of Junio C Hamano [gitster@pobox.com]
Sent: Monday, October 12, 2015 10:55 AM
To: Victor Leschuk
Cc: git@vger.kernel.org; vleschuk@gmail.com
Subject: Re: thread-utils: build with NO_PTHREADS fails

Junio C Hamano <gitster@pobox.com> writes:

> Victor Leschuk <vleschuk@accesssoftek.com> writes:
>
>> 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)
>> {
>>     // ...
>> }
>
> Yeah, that is obviously incorrect.
> ...

Well, no, I spoke too early.  I do not see there is much wrong here.

There is this bit in the Makefile:

        ifdef NO_PTHREADS
                BASIC_CFLAGS += -DNO_PTHREADS
        else
                BASIC_CFLAGS += $(PTHREAD_CFLAGS)
                EXTLIBS += $(PTHREAD_LIBS)
                LIB_OBJS += thread-utils.o
        endif

The source file thread-utils.c is not compiled to thread-utils.o if
you say NO_PTHREADS, and the resulting libgit.a does not of course
have it.

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2015-10-14 11:25 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-11 12:58 thread-utils: build with NO_PTHREADS fails Victor Leschuk
2015-10-12 15:57 ` Junio C Hamano
2015-10-12 17:55   ` Junio C Hamano
2015-10-14 11:24     ` Victor Leschuk

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.