hf mf fchk - output style
[RRG-proxmark3.git] / tools / hitag2crack / crack5opencl / threads.h
blob6aa958fad47951e0709ca0e30edc61a695474b17
1 /****************************************************************************
3 Author : Gabriele 'matrix' Gristina <gabriele.gristina@gmail.com>
4 Date : Sun Jan 10 13:59:37 CET 2021
5 Version: 0.1beta
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 ****************************************************************************/
25 #ifndef THREADS_H
26 #define THREADS_H
28 #include <stdio.h>
29 #include <stdarg.h>
30 #include <stdbool.h>
31 #include <pthread.h>
33 #include "ht2crack5opencl.h"
34 #include "opencl.h"
35 #include "hitag2.h"
37 typedef enum thread_status {
38 TH_START = 0,
39 TH_WAIT,
40 TH_PROCESSING,
41 TH_ERROR,
42 TH_FOUND_KEY,
43 TH_END
45 } thread_status_t;
47 typedef enum thread_type {
48 THREAD_TYPE_SEQ = 0,
49 THREAD_TYPE_ASYNC
51 } thread_type_t;
53 typedef enum thread_error {
54 THREAD_NOERROR = 0,
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
71 } thread_error_t;
73 typedef struct threads_ctx {
74 short init;
75 short type;
77 unsigned char pad1[4];
78 size_t thread_count;
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;
92 pthread_attr_t attr;
93 pthread_mutexattr_t mutex_attr;
95 unsigned char pad3[4];
96 } thread_ctx_t;
98 // used by threads engine
99 typedef struct thread_arg {
100 thread_status_t status;
101 unsigned char pad1[4];
102 size_t max_threads;
104 uint64_t s;
105 uint32_t uid, nR1, aR1, nR2, aR2;
106 bool r;
107 bool err;
108 bool quit;
110 unsigned char pad2[1];
111 uint64_t off;
112 uint64_t *matches;
113 uint32_t *matches_found;
114 size_t slice;
115 size_t max_slices;
116 size_t device_id;
118 uint64_t key;
120 opencl_ctx_t *ocl_ctx;
121 thread_ctx_t *thread_ctx;
123 } thread_args_t;
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);
139 #endif // THREADS_H