Re: [PATCH 01/10] thread-utils: macros to unconditionally compile pthreads API
- From
Duy Nguyen <pclouds@gmail.com>
- Date
- Oct 27, 2018, 14:43 UTC
- Message-ID
- <CACsJy8DLW_smOJd6aCoRcJZxQ2Lzut5US=sPadj7=fhne0UHGg@mail.gmail.com>
- In-Reply-To
- <20181027081538.GG26685@sigill.intra.peff.net>
On Sat, Oct 27, 2018 at 10:15 AM Jeff King <peff@peff.net> wrote:
Show 20 quoted lines
>
> On Sat, Oct 27, 2018 at 09:40:13AM +0200, Duy Nguyen wrote:
>
> > > We expect to be able to store a void pointer here and get it back, which
> > > should work even for a single thread. Do we need something like:
> > >
> > > extern void *pthread_specific_data;
> > >
> > > #define pthread_setspecific(key, data) do { \
> > > pthread_specific_data = data; \
> > > } while(0)
> > >
> > > void pthread_getspecific(key) pthread_specific_data
> >
> > The data is per key though so a correct implementation may involve a
> > hashmap or a list.
>
> Ah, yeah, you're right, I was mixing up the thread id and the key in my
> head. I think it would just be an array of void pointers, with
> pthread_key_create() returning an static index.We could redefine pthread_key_t as "void *" though, then _setspecific(key, data) is key = data; But there will be more changes in index-pack.c to take advantage of it. I took a stab but couldn't figure out fast enough where _setspecific(.., ¬hread_data) should be called in NO_PTHREADS mode (to simplify get_thread_data() to just a wrapper of _getspecific) and got bored. It could be a micro project for someone really wants to learn about index-pack.c
-- Duy