Subject: Re: What's cooking in git.git (Sep 2016, #08; Tue, 27)

From: Junio C Hamano <[email-masked]>
Date: Mon, 03 Oct 2016 13:49:53 -0700

Stefan Beller <[email-masked]> writes:

> I am looking at the tip of jc/attr-more and for a minimum
> thread safety we'd want to change the call sites to be aware of the
> threads, i.e. instead of doing
>
      static struct git_attr_check *check;	
>     if (!check)
>         check = git_attr_check_initl("crlf", "ident",
>                     "filter", "eol", "text",
>                     NULL);
>
> We'd rather call
>
>         struct git_attr_check *check;
>         check = git_attr_check_lookup_or_initl_threadsafe(
>                 "crlf", "ident", "filter", "eol", "text", NULL);
>          if (!git_check_attr(path, check)) {
>              ...

I actually am hoping that the "static" can be kept so that we can
minimize the cost of interning these symbols into struct git_attr.

The initialization would thus become something like:

	static struct git_attr_check *check;
	git_attr_check_initl(&check, "crlf", "ident", ..., NULL);

The structure will have an array of git_attr[], once interned will
be shared and used by everybody.  _initl() will need to make sure
that the "check" pointer is updated atomically so that multiple
people racing to initialize this variable will not step on each
others' toes.

Then the use site would do something like

	const char *result[... some size ...];
	git_check_attr(path, check, result[]);

to receive result regardless of anybody else who is using the same
"check" structure to ask the same question (for different paths).