git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH] sha1-name: make sort_ambiguous_oid_array() thread-safe
@ 2019-08-20 18:49 René Scharfe
  2019-08-20 18:57 ` Derrick Stolee
  0 siblings, 1 reply; 2+ messages in thread
From: René Scharfe @ 2019-08-20 18:49 UTC (permalink / raw)
  To: Git Mailing List; +Cc: Junio C Hamano, Nguyễn Thái Ngọc Duy

Use QSORT_S instead of QSORT, which allows passing the repository
pointer to the comparison function without using a static variable.

Signed-off-by: René Scharfe <l.s.r@web.de>
---
 sha1-name.c | 9 +++------
 1 file changed, 3 insertions(+), 6 deletions(-)

diff --git a/sha1-name.c b/sha1-name.c
index 2989e27b71..c665e3f96d 100644
--- a/sha1-name.c
+++ b/sha1-name.c
@@ -403,9 +403,9 @@ static int repo_collect_ambiguous(struct repository *r,
 	return collect_ambiguous(oid, data);
 }

-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);
 }

 static enum get_oid_result get_short_oid(struct repository *r,
--
2.23.0

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

* Re: [PATCH] sha1-name: make sort_ambiguous_oid_array() thread-safe
  2019-08-20 18:49 [PATCH] sha1-name: make sort_ambiguous_oid_array() thread-safe René Scharfe
@ 2019-08-20 18:57 ` Derrick Stolee
  0 siblings, 0 replies; 2+ messages in thread
From: Derrick Stolee @ 2019-08-20 18:57 UTC (permalink / raw)
  To: René Scharfe, Git Mailing List
  Cc: Junio C Hamano, Nguyễn Thái Ngọc Duy

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.

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

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

end of thread, other threads:[~2019-08-20 18:57 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-20 18:49 [PATCH] sha1-name: make sort_ambiguous_oid_array() thread-safe René Scharfe
2019-08-20 18:57 ` Derrick Stolee

Code repositories for project(s) associated with this public 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).