git@vger.kernel.org list mirror (unofficial, one of many)
 help / color / mirror / code / Atom feed
From: Jeff Hostetler <git@jeffhostetler.com>
To: Jeff King <peff@peff.net>
Cc: "Jeff Hostetler via GitGitGadget" <gitgitgadget@gmail.com>,
	"Jeff Hostetler" <jeffhost@microsoft.com>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
	git@vger.kernel.org, "Junio C Hamano" <gitster@pobox.com>
Subject: Re: [PATCH 0/1] trace2: fix tracing when NO_PTHREADS is defined
Date: Thu, 23 May 2019 09:55:12 -0400	[thread overview]
Message-ID: <50badedb-7856-374e-b14c-1eb1951c63f0@jeffhostetler.com> (raw)
In-Reply-To: <20190523055108.GA20871@sigill.intra.peff.net>



On 5/23/2019 1:51 AM, Jeff King wrote:
> On Wed, May 22, 2019 at 09:23:39AM -0400, Jeff Hostetler wrote:
> 
>> I was wondering about that too as the proper long term solution.
>> We would need (as the discussion suggests [1]) to properly
>> respect/represent the pthread_key_t argument.
>>
>> For now, I've guarded my usage of pthread_getspecific() in the trace2
>> (similar to what index-pack does), so its not urgent that we update it.
>> And I'd rather we take this simple trace2 fix now and not try to combine
>> it with fixes for the pthread macros.  Especially now as we're in the RC
>> cycle for 2.22.
> 
> Yeah, I think that makes sense.
> 
>> I'll make a note to revisit the pthread code after 2.22.
> 
> For fun, here's a constant-time zero-allocation implementation that I
> came up with. It passes t0211 with NO_PTHREADS, but I didn't test it
> beyond that.
> 
> diff --git a/thread-utils.h b/thread-utils.h
> index 4961487ed9..f466215742 100644
> --- a/thread-utils.h
> +++ b/thread-utils.h
> @@ -18,7 +18,7 @@
>   #define pthread_t int
>   #define pthread_mutex_t int
>   #define pthread_cond_t int
> -#define pthread_key_t int
> +#define pthread_key_t git_pthread_key_t
>   
>   #define pthread_mutex_init(mutex, attr) dummy_pthread_init(mutex)
>   #define pthread_mutex_lock(mutex)
> @@ -31,16 +31,49 @@
>   #define pthread_cond_broadcast(cond)
>   #define pthread_cond_destroy(cond)
>   
> -#define pthread_key_create(key, attr) dummy_pthread_init(key)
> -#define pthread_key_delete(key)
> +#define pthread_key_create(key, destroy) git_pthread_key_create(key, destroy)
> +#define pthread_key_delete(key) git_pthread_key_delete(key)
>   
>   #define pthread_create(thread, attr, fn, data) \
>   	dummy_pthread_create(thread, attr, fn, data)
>   #define pthread_join(thread, retval) \
>   	dummy_pthread_join(thread, retval)
>   
> -#define pthread_setspecific(key, data)
> -#define pthread_getspecific(key) NULL
> +#define pthread_setspecific(key, data) git_pthread_setspecific(key, data)
> +#define pthread_getspecific(key) git_pthread_getspecific(key)
> +
> +typedef struct {
> +	void *data;
> +	/* extra indirection because setspecific is passed key by value */
> +	void **vdata;
> +} git_pthread_key_t;
> +
> +static inline int git_pthread_key_create(git_pthread_key_t *key,
> +					 void (*destroy)(void *))
> +{
> +	key->data = NULL;
> +	key->vdata = &key->data;
> +	/* We don't use this; alternatively we could all via atexit(). */
> +	if (destroy)
> +		BUG("NO_PTHREADS does not support pthread key destructors");
> +	return 0;
> +}
> +
> +static inline int git_pthread_key_delete(git_pthread_key_t key)
> +{
> +	/* noop */
> +	return 0;
> +}
> +
> +static inline void git_pthread_setspecific(git_pthread_key_t key, void *data)
> +{
> +	*(key.vdata) = data;
> +}
> +
> +static inline void *git_pthread_getspecific(git_pthread_key_t key)
> +{
> +	return key.data;
> +}
>   
>   int dummy_pthread_create(pthread_t *pthread, const void *attr,
>   			 void *(*fn)(void *), void *data);
> 

Thanks!  I'll play with this and submit something after 2.22 and
things slow down a bit.

Jeff


  reply	other threads:[~2019-05-23 13:55 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-21 19:33 Jeff Hostetler via GitGitGadget
2019-05-21 19:33 ` [PATCH 1/1] " Jeff Hostetler via GitGitGadget
2019-05-21 21:27 ` [PATCH 0/1] " Jeff King
2019-05-22 13:23   ` Jeff Hostetler
2019-05-23  5:51     ` Jeff King
2019-05-23 13:55       ` Jeff Hostetler [this message]
2019-05-25 10:43       ` Duy Nguyen
2019-05-28  6:28         ` Jeff King
2019-05-28 14:57           ` Jeff Hostetler
2019-05-28 17:14     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50badedb-7856-374e-b14c-1eb1951c63f0@jeffhostetler.com \
    --to=git@jeffhostetler.com \
    --cc=git@vger.kernel.org \
    --cc=gitgitgadget@gmail.com \
    --cc=gitster@pobox.com \
    --cc=jeffhost@microsoft.com \
    --cc=pclouds@gmail.com \
    --cc=peff@peff.net \
    --subject='Re: [PATCH 0/1] trace2: fix tracing when NO_PTHREADS is defined' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Code repositories for project(s) associated with this inbox:

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).