diff options
Diffstat (limited to 'src/argon2-thread.c')
-rw-r--r-- | src/argon2-thread.c | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/argon2-thread.c b/src/argon2-thread.c new file mode 100644 index 0000000..b554ae7 --- /dev/null +++ b/src/argon2-thread.c @@ -0,0 +1,36 @@ +#include "argon2-thread.h" +#if defined(_WIN32) +#include <windows.h> +#endif + +int argon2_thread_create(argon2_thread_handle_t *handle, + argon2_thread_func_t func, void *args) { + if (NULL == handle || func == NULL) { + return -1; + } +#if defined(_WIN32) + *handle = _beginthreadex(NULL, 0, func, args, 0, NULL); + return *handle != 0 ? 0 : -1; +#else + return pthread_create(handle, NULL, func, args); +#endif +} + +int argon2_thread_join(argon2_thread_handle_t handle) { +#if defined(_WIN32) + if (WaitForSingleObject((HANDLE)handle, INFINITE) == WAIT_OBJECT_0) { + return CloseHandle((HANDLE)handle) != 0 ? 0 : -1; + } + return -1; +#else + return pthread_join(handle, NULL); +#endif +} + +void argon2_thread_exit(void) { +#if defined(_WIN32) + _endthreadex(0); +#else + pthread_exit(NULL); +#endif +} |