Re: [PATCH 2/2] hex: make hash_to_hex_algop() and friends thread-safe
- From
brian m. carlson <sandals@crustytoothpaste.net>
- Date
- Jun 25, 2020, 23:07 UTC
- Message-ID
- <20200625230753.GB9782@camp.crustytoothpaste.net>
- In-Reply-To
- <0104cd9c763aee220a2df357834c79b10695ee35.1593115455.git.matheus.bernardino@usp.br>
On 2020-06-25 at 20:32:57, Matheus Tavares wrote:
Show 7 quoted lines
> +#ifdef HAVE_THREADS
> + void *value;
> +
> + if (pthread_once(&hexbuf_array_once, init_hexbuf_array_key))
> + die(_("failed to initialize threads' key for hash to hex conversion"));
> +
> + value = pthread_key_getspecific(&hexbuf_array_key);I think the portable name for this is "pthread_getspecific". That appears to be what POSIX specifies and what our Windows pthread compat code uses.
Show 5 quoted lines
> + if (value) {
> + ha = (struct hexbuf_array *) value;
> + } else {
> + ha = xmalloc(sizeof(*ha));
> + if (pthread_key_setspecific(&hexbuf_array_key, (void *)ha))Same thing here.
Show 11 quoted lines
> + die(_("failed to set thread buffer for hash to hex conversion"));
> + }
> +#else
> + ha = &default_hexbuf_array;
> +#endif
> +
> + ha->idx = (ha->idx + 1) % ARRAY_SIZE(ha->bufs);
> + return hash_to_hex_algop_r(ha->bufs[ha->idx], hash, algop);
> }
>
> char *hash_to_hex(const unsigned char *hash)-- brian m. carlson: Houston, Texas, US OpenPGP: https://keybase.io/bk2204