1 /****************************************************************************
3 Author : Gabriele 'matrix' Gristina <gabriele.gristina@gmail.com>
4 Date : Sun Jan 10 13:59:37 CET 2021
6 License: GNU General Public License v3 or any later version (see LICENSE.txt)
8 *****************************************************************************
9 Copyright (C) 2020-2021 <Gabriele Gristina>
11 This program is free software: you can redistribute it and/or modify
12 it under the terms of the GNU General Public License as published by
13 the Free Software Foundation, either version 3 of the License, or
14 (at your option) any later version.
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
21 You should have received a copy of the GNU General Public License
22 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 ****************************************************************************/
33 #include "ht2crack5opencl.h"
37 typedef enum thread_status
{
47 typedef enum thread_type
{
53 typedef enum thread_error
{
55 THREAD_ERROR_CTX_IS_NULL
= -1,
56 THREAD_ERROR_CTX_IS_INIT
= -2,
57 THREAD_ERROR_TYPE_INVALID
= -3,
58 THREAD_ERROR_COUNT_INVALID
= -4,
59 THREAD_ERROR_ATTR_SETDETACH
= -5,
60 THREAD_ERROR_ATTR
= -6,
61 THREAD_ERROR_MUTEXATTR
= -7,
62 THREAD_ERROR_CREATE
= -8,
63 THREAD_ERROR_MUTEX
= -9,
64 THREAD_ERROR_COND
= -10,
65 THREAD_ERROR_MUTEX_USLEEP
= -11,
66 THREAD_ERROR_COND_USLEEP
= -12,
67 THREAD_ERROR_GENERIC
= -13,
68 THREAD_ERROR_ALLOC
= -14,
69 THREAD_ERROR_INTERNAL
= -15
73 typedef struct threads_ctx
{
77 unsigned char pad1
[4];
80 pthread_t
*thread_handles
;
82 pthread_mutex_t
*thread_mutexs
;
83 pthread_cond_t
*thread_conds
;
85 short enable_condusleep
;
87 // get rid of sleep/usleep call to synchronize threads
88 unsigned char pad2
[6];
89 pthread_mutex_t thread_mutex_usleep
;
90 pthread_cond_t thread_cond_usleep
;
93 pthread_mutexattr_t mutex_attr
;
95 unsigned char pad3
[4];
98 // used by threads engine
99 typedef struct thread_arg
{
100 thread_status_t status
;
101 unsigned char pad1
[4];
105 uint32_t uid
, nR1
, aR1
, nR2
, aR2
;
110 unsigned char pad2
[1];
113 uint32_t *matches_found
;
120 opencl_ctx_t
*ocl_ctx
;
121 thread_ctx_t
*thread_ctx
;
125 int thread_init(thread_ctx_t
*ctx
, short type
, size_t thread_count
);
126 int thread_start(thread_ctx_t
*ctx
, thread_args_t
*t_arg
);
127 int thread_stop(thread_ctx_t
*ctx
);
128 int thread_start_scheduler(thread_ctx_t
*ctx
, thread_args_t
*t_arg
, wu_queue_ctx_t
*queue_ctx
);
129 bool thread_setEnd(thread_ctx_t
*ctx
, thread_args_t
*t_arg
);
131 const char *thread_strerror(int error
);
132 const char *thread_status_strdesc(thread_status_t s
);
134 void *computing_process(void *arg
);
135 void *computing_process_async(void *arg
);
137 int thread_destroy(thread_ctx_t
*ctx
);