aboutsummaryrefslogtreecommitdiffstats
path: root/libblake_init.c
blob: 0276cd2ea39885da7cb6ee76c0da059e5707669a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/* See LICENSE file for copyright and license details. */
#include "common.h"
#include <stdatomic.h>

#if defined(__GNUC__)
__attribute__((__constructor__)) /* ignored if statically linked, so this function shall
                                  * by the application, we just use the constructor (init)
                                  * attribute in case that is forgotten, as it will only
                                  * improve performance, but the library with function
                                  * perfectly fine even if it's not called */
#endif
void
libblake_init(void)
{
	static volatile int initialised = 0;
	static volatile atomic_flag spinlock = ATOMIC_FLAG_INIT;

	if (initialised)
		return;

	while (atomic_flag_test_and_set(&spinlock));

	if (!initialised) {
		/* libblake_internal_blake2b_compress_mm128_init(); */
		/* libblake_internal_blake2b_compress_mm256_init(); */
		initialised = 1;
	}

	atomic_flag_clear(&spinlock);
}