Coverage Report

Created: 2025-07-07 10:01

/work/workdir/UnpackedTarball/argon2/src/thread.c
Line
Count
Source (jump to first uncovered line)
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
#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
0
                         argon2_thread_func_t func, void *args) {
27
0
    if (NULL == handle || func == NULL) {
28
0
        return -1;
29
0
    }
30
#if defined(_WIN32)
31
    *handle = _beginthreadex(NULL, 0, func, args, 0, NULL);
32
    return *handle != 0 ? 0 : -1;
33
#else
34
0
    return pthread_create(handle, NULL, func, args);
35
0
#endif
36
0
}
37
38
0
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
0
    return pthread_join(handle, NULL);
46
0
#endif
47
0
}
48
49
0
void argon2_thread_exit(void) {
50
#if defined(_WIN32)
51
    _endthreadex(0);
52
#else
53
0
    pthread_exit(NULL);
54
0
#endif
55
0
}
56
57
#endif /* ARGON2_NO_THREADS */