git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] sha1-name: make sort_ambiguous_oid_array() thread-safe

From
Derrick Stolee <stolee@gmail.com>
Date
Aug 20, 2019, 18:57 UTC
Message-ID
<7000e687-800b-c613-aa90-e022bd30a023@gmail.com>
In-Reply-To
<a08751c7-170d-7faf-272e-79c589ec3eab@web.de>
On 8/20/2019 2:49 PM, René Scharfe wrote:
> Use QSORT_S instead of QSORT, which allows passing the repository
> pointer to the comparison function without using a static variable.
Makes sense.
Show 18 quoted lines
> -static struct repository *sort_ambiguous_repo;
> -static int sort_ambiguous(const void *a, const void *b)
> +static int sort_ambiguous(const void *a, const void *b, void *ctx)
>  {
> +	struct repository *sort_ambiguous_repo = ctx;
>  	int a_type = oid_object_info(sort_ambiguous_repo, a, NULL);
>  	int b_type = oid_object_info(sort_ambiguous_repo, b, NULL);
>  	int a_type_sort;
> @@ -434,10 +434,7 @@ static int sort_ambiguous(const void *a, const void *b)
> 
>  static void sort_ambiguous_oid_array(struct repository *r, struct oid_array *a)
>  {
> -	/* mutex will be needed if this code is to be made thread safe */
> -	sort_ambiguous_repo = r;
> -	QSORT(a->oid, a->nr, sort_ambiguous);
> -	sort_ambiguous_repo = NULL;
> +	QSORT_S(a->oid, a->nr, sort_ambiguous, r);
>  }
LGTM!

Thanks, -Stolee

Previous: René Scharfe
Message 2 of 2 in “sha1-name: make sort_ambiguous_oid_array() thread-safe”
  1. sha1-name: make sort_ambiguous_oid_array() thread-safeRené Scharfe, Aug 20, 2019
  2. Derrick StoleeAug 20, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.