|
Packit |
94f725 |
/*
|
|
Packit |
94f725 |
* Argon2 reference source code package - reference C implementations
|
|
Packit |
94f725 |
*
|
|
Packit |
94f725 |
* Copyright 2015
|
|
Packit |
94f725 |
* Daniel Dinu, Dmitry Khovratovich, Jean-Philippe Aumasson, and Samuel Neves
|
|
Packit |
94f725 |
*
|
|
Packit |
94f725 |
* You may use this work under the terms of a Creative Commons CC0 1.0
|
|
Packit |
94f725 |
* License/Waiver or the Apache Public License 2.0, at your option. The terms of
|
|
Packit |
94f725 |
* these licenses can be found at:
|
|
Packit |
94f725 |
*
|
|
Packit |
94f725 |
* - CC0 1.0 Universal : http://creativecommons.org/publicdomain/zero/1.0
|
|
Packit |
94f725 |
* - Apache 2.0 : http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
94f725 |
*
|
|
Packit |
94f725 |
* You should have received a copy of both of these licenses along with this
|
|
Packit |
94f725 |
* software. If not, they may be obtained at the above URLs.
|
|
Packit |
94f725 |
*/
|
|
Packit |
94f725 |
|
|
Packit |
94f725 |
#if !defined(ARGON2_NO_THREADS)
|
|
Packit |
94f725 |
|
|
Packit |
94f725 |
#include "thread.h"
|
|
Packit |
94f725 |
#if defined(_WIN32)
|
|
Packit |
94f725 |
#include <windows.h>
|
|
Packit |
94f725 |
#endif
|
|
Packit |
94f725 |
|
|
Packit |
94f725 |
int argon2_thread_create(argon2_thread_handle_t *handle,
|
|
Packit |
94f725 |
argon2_thread_func_t func, void *args) {
|
|
Packit |
94f725 |
if (NULL == handle || func == NULL) {
|
|
Packit |
94f725 |
return -1;
|
|
Packit |
94f725 |
}
|
|
Packit |
94f725 |
#if defined(_WIN32)
|
|
Packit |
94f725 |
*handle = _beginthreadex(NULL, 0, func, args, 0, NULL);
|
|
Packit |
94f725 |
return *handle != 0 ? 0 : -1;
|
|
Packit |
94f725 |
#else
|
|
Packit |
94f725 |
return pthread_create(handle, NULL, func, args);
|
|
Packit |
94f725 |
#endif
|
|
Packit |
94f725 |
}
|
|
Packit |
94f725 |
|
|
Packit |
94f725 |
int argon2_thread_join(argon2_thread_handle_t handle) {
|
|
Packit |
94f725 |
#if defined(_WIN32)
|
|
Packit |
94f725 |
if (WaitForSingleObject((HANDLE)handle, INFINITE) == WAIT_OBJECT_0) {
|
|
Packit |
94f725 |
return CloseHandle((HANDLE)handle) != 0 ? 0 : -1;
|
|
Packit |
94f725 |
}
|
|
Packit |
94f725 |
return -1;
|
|
Packit |
94f725 |
#else
|
|
Packit |
94f725 |
return pthread_join(handle, NULL);
|
|
Packit |
94f725 |
#endif
|
|
Packit |
94f725 |
}
|
|
Packit |
94f725 |
|
|
Packit |
94f725 |
void argon2_thread_exit(void) {
|
|
Packit |
94f725 |
#if defined(_WIN32)
|
|
Packit |
94f725 |
_endthreadex(0);
|
|
Packit |
94f725 |
#else
|
|
Packit |
94f725 |
pthread_exit(NULL);
|
|
Packit |
94f725 |
#endif
|
|
Packit |
94f725 |
}
|
|
Packit |
94f725 |
|
|
Packit |
94f725 |
#endif /* ARGON2_NO_THREADS */
|