1/*
2 * Argon2 reference source code package - reference C implementations
3 *
4 * Copyright 2015
5 * Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves
6 *
7 * You may use this work under the terms of a Creative Commons CC0 1.0
8 * License/Waiver or the Apache Public License 2.0, at your option. The terms of
9 * these licenses can be found at:
10 *
11 * - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
12 * - Apache 2.0        : http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * You should have received a copy of both of these licenses along with this
15 * software. If not, they may be obtained at the above URLs.
16 */
17
18#ifndef ARGON2_THREAD_H
19#define ARGON2_THREAD_H
20
21#if !defined(ARGON2_NO_THREADS)
22
23/*
24        Here we implement an abstraction layer for the simp��e requirements
25        of the Argon2 code. We only require 3 primitives---thread creation,
26        joining, and termination---so full emulation of the pthreads API
27        is unwarranted. Currently we wrap pthreads and Win32 threads.
28
29        The API defines 2 types: the function pointer type,
30   argon2_thread_func_t,
31        and the type of the thread handle---argon2_thread_handle_t.
32*/
33#if defined(_WIN32)
34#include <process.h>
35typedef unsigned(__stdcall *argon2_thread_func_t)(void *);
36typedef uintptr_t argon2_thread_handle_t;
37#else
38#include <pthread.h>
39typedef void *(*argon2_thread_func_t)(void *);
40typedef pthread_t argon2_thread_handle_t;
41#endif
42
43/* Creates a thread
44 * @param handle pointer to a thread handle, which is the output of this
45 * function. Must not be NULL.
46 * @param func A function pointer for the thread's entry point. Must not be
47 * NULL.
48 * @param args Pointer that is passed as an argument to @func. May be NULL.
49 * @return 0 if @handle and @func are valid pointers and a thread is successfully
50 * created.
51 */
52int argon2_thread_create(argon2_thread_handle_t *handle,
53                         argon2_thread_func_t func, void *args);
54
55/* Waits for a thread to terminate
56 * @param handle Handle to a thread created with argon2_thread_create.
57 * @return 0 if @handle is a valid handle, and joining completed successfully.
58*/
59int argon2_thread_join(argon2_thread_handle_t handle);
60
61/* Terminate the current thread. Must be run inside a thread created by
62 * argon2_thread_create.
63*/
64void argon2_thread_exit(void) __attribute__((__noreturn__));
65
66#endif /* ARGON2_NO_THREADS */
67#endif
68