"Fossies" - the Fresh Open Source Software Archive

Member "cryptsetup-2.4.3/lib/crypto_backend/argon2/thread.c" (13 Jan 2022, 1558 Bytes) of package /linux/misc/cryptsetup-2.4.3.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "thread.c" see the Fossies "Dox" file reference documentation.

    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 : https://creativecommons.org/publicdomain/zero/1.0
   12  * - Apache 2.0        : https://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 #if !defined(ARGON2_NO_THREADS)
   19 
   20 #include "thread.h"
   21 #if defined(_WIN32)
   22 #include <windows.h>
   23 #endif
   24 
   25 int argon2_thread_create(argon2_thread_handle_t *handle,
   26                          argon2_thread_func_t func, void *args) {
   27     if (NULL == handle || func == NULL) {
   28         return -1;
   29     }
   30 #if defined(_WIN32)
   31     *handle = _beginthreadex(NULL, 0, func, args, 0, NULL);
   32     return *handle != 0 ? 0 : -1;
   33 #else
   34     return pthread_create(handle, NULL, func, args);
   35 #endif
   36 }
   37 
   38 int argon2_thread_join(argon2_thread_handle_t handle) {
   39 #if defined(_WIN32)
   40     if (WaitForSingleObject((HANDLE)handle, INFINITE) == WAIT_OBJECT_0) {
   41         return CloseHandle((HANDLE)handle) != 0 ? 0 : -1;
   42     }
   43     return -1;
   44 #else
   45     return pthread_join(handle, NULL);
   46 #endif
   47 }
   48 
   49 void argon2_thread_exit(void) {
   50 #if defined(_WIN32)
   51     _endthreadex(0);
   52 #else
   53     pthread_exit(NULL);
   54 #endif
   55 }
   56 
   57 #endif /* ARGON2_NO_THREADS */