aboutsummaryrefslogtreecommitdiffstats
path: root/libblake_init.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--libblake_init.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/libblake_init.c b/libblake_init.c
new file mode 100644
index 0000000..ebf0e34
--- /dev/null
+++ b/libblake_init.c
@@ -0,0 +1,27 @@
+/* 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 incase 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;
+
+ 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);
+}