Merge pull request #2654 from Antiklesys/master
[RRG-proxmark3.git] / tools / hitag2crack / crack5opencl / dolphin_macro.h
blobdb7766a873bfbaa00dea97751f5386fea719315b
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 ****************************************************************************/
26 // trust me...i'm a dolphin :P
27 // too many allocations, too many free to manage, I need dolphin macros :)
28 // they could be buggy, but if you know how to fix them, do it
30 #define MEMORY_FREE_ADD(a) { \
31 freeList[freeListIdx++] = (void *)(a); \
34 #define MEMORY_FREE_ALL { \
35 int t = freeListIdx; \
36 while (t-- > 0) { \
37 if (freeList[t] != NULL) { \
38 free (freeList[t]); \
39 freeList[t] = NULL; \
41 } \
42 if (freeList != NULL) { \
43 free (freeList); \
44 freeList = NULL; \
45 } \
48 #define MEMORY_FREE_DEL(a) { \
49 for (int i = 0; i < freeListIdx; i++) { \
50 if (freeList[i] && a == freeList[i]) { \
51 free(freeList[i]); \
52 freeList[i] = NULL; \
53 break; \
54 } \
55 } \
58 #define MEMORY_FREE_LIST(a,i) { \
59 if (i > 0) { \
60 int t=(int)i; \
61 do { \
62 if (a[t] != NULL) { \
63 free(a[t]); \
64 a[t]=NULL; \
65 } \
66 } while (--t >= 0); \
67 MEMORY_FREE_DEL(a) \
68 } \
71 #define MEMORY_FREE_LIST_Z(a,i) { \
72 int t = (int)i; \
73 do { \
74 if (a[t] != NULL) { \
75 free(a[t]); \
76 a[t] = NULL; \
77 } \
78 } while (--t >= 0); \
79 MEMORY_FREE_DEL(a) \
82 #define MEMORY_FREE_OPENCL(c,i) { \
83 int t = (int)i; \
84 do { \
85 if (c.contexts[t]) \
86 clReleaseContext (c.contexts[t]); \
87 if (c.keystreams[t]) \
88 clReleaseMemObject (c.keystreams[t]); \
89 if (c.candidates[t]) \
90 clReleaseMemObject (c.candidates[t]); \
91 if (c.matches[t]) \
92 clReleaseMemObject (c.matches[t]); \
93 if (c.matches_found[t]) \
94 clReleaseMemObject (c.matches_found[t]); \
95 if (c.commands[t]) \
96 clReleaseCommandQueue (c.commands[t]); \
97 if (c.kernels[t]) \
98 clReleaseKernel (c.kernels[t]); \
99 if (c.programs[t]) \
100 clReleaseProgram (c.programs[t]); \
101 } while (--t >= 0); \