From 3adbf3d0d50415b500d30e98161bfd58bb8c92db Mon Sep 17 00:00:00 2001 From: jsteube Date: Tue, 20 Sep 2016 13:18:47 +0200 Subject: [PATCH] Move global mux_dispatcher variable into opencl_ctx_t --- include/thread.h | 8 -------- include/types.h | 20 ++++++++++++++------ src/autotune.c | 1 + src/data.c | 1 + src/dispatch.c | 20 +++++++++----------- src/hash_management.c | 2 +- src/hashcat.c | 5 +---- src/hlfmt.c | 2 +- src/hwmon.c | 2 +- src/logfile.c | 1 + src/monitor.c | 2 +- src/mpsp.c | 2 +- src/opencl.c | 5 ++++- src/outfile_check.c | 2 +- src/restore.c | 2 +- src/rp_cpu.c | 2 +- src/status.c | 2 +- src/stdout.c | 2 +- src/terminal.c | 2 +- src/thread.c | 2 +- src/tuningdb.c | 1 + src/weak_hash.c | 1 + src/wordlist.c | 2 +- 23 files changed, 46 insertions(+), 43 deletions(-) diff --git a/include/thread.h b/include/thread.h index 5831bd8b1..34c04a9d6 100644 --- a/include/thread.h +++ b/include/thread.h @@ -16,14 +16,6 @@ #include #endif // _WIN -#if defined (_WIN) -typedef HANDLE hc_thread_t; -typedef CRITICAL_SECTION hc_thread_mutex_t; -#elif defined (_POSIX) -typedef pthread_t hc_thread_t; -typedef pthread_mutex_t hc_thread_mutex_t; -#endif - #if defined (_WIN) #define hc_thread_create(t,f,a) t = CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE) &f, a, 0, NULL) diff --git a/include/types.h b/include/types.h index 8e3c16fc4..c41ca2a2f 100644 --- a/include/types.h +++ b/include/types.h @@ -45,12 +45,22 @@ typedef uint32_t uint; // we need to get rid of this sooner or later, for consis // timer #if defined (_WIN) -typedef LARGE_INTEGER hc_timer_t; +typedef LARGE_INTEGER hc_timer_t; #elif defined (_POSIX) -typedef struct timeval hc_timer_t; +typedef struct timeval hc_timer_t; #endif +// thread +#if defined (_WIN) +typedef HANDLE hc_thread_t; +typedef CRITICAL_SECTION hc_thread_mutex_t; +#elif defined (_POSIX) +typedef pthread_t hc_thread_t; +typedef pthread_mutex_t hc_thread_mutex_t; +#endif + +// enums typedef enum wl_mode { @@ -67,7 +77,6 @@ typedef enum hl_mode } hl_mode_t; - typedef struct { char *file_name; @@ -76,7 +85,6 @@ typedef struct } outfile_data_t; - typedef enum attack_mode { ATTACK_MODE_STRAIGHT = 0, @@ -526,6 +534,8 @@ typedef struct int force_jit_compilation; + hc_thread_mutex_t mux_dispatcher; + } opencl_ctx_t; #if defined (__APPLE__) @@ -789,8 +799,6 @@ typedef struct * threads */ - - opencl_ctx_t *opencl_ctx; u32 shutdown_inner; diff --git a/src/autotune.c b/src/autotune.c index 4a0f07b2d..cd7aee160 100644 --- a/src/autotune.c +++ b/src/autotune.c @@ -16,6 +16,7 @@ #include "mpsp.h" #include "rp_cpu.h" #include "tuningdb.h" +#include "thread.h" #include "opencl.h" #include "hwmon.h" #include "restore.h" diff --git a/src/data.c b/src/data.c index f12dda823..0fad8a4e9 100644 --- a/src/data.c +++ b/src/data.c @@ -15,6 +15,7 @@ #include "mpsp.h" #include "rp_cpu.h" #include "tuningdb.h" +#include "thread.h" #include "opencl.h" #include "hwmon.h" #include "restore.h" diff --git a/src/dispatch.c b/src/dispatch.c index ecc0089fe..87083a324 100644 --- a/src/dispatch.c +++ b/src/dispatch.c @@ -16,11 +16,11 @@ #include "ext_nvml.h" #include "ext_xnvctrl.h" #include "tuningdb.h" +#include "thread.h" #include "opencl.h" #include "hwmon.h" #include "restore.h" #include "hash_management.h" -#include "thread.h" #include "rp_cpu.h" #include "terminal.h" #include "mpsp.h" @@ -40,8 +40,6 @@ extern hc_global_data_t data; extern hc_thread_mutex_t mux_counter; -hc_thread_mutex_t mux_dispatcher; - static void set_kernel_power_final (const u64 kernel_power_final) { if (data.quiet == 0) @@ -79,9 +77,9 @@ static u32 get_power (hc_device_param_t *device_param) return device_param->kernel_power; } -static uint get_work (hc_device_param_t *device_param, const u64 max) +static uint get_work (opencl_ctx_t *opencl_ctx, hc_device_param_t *device_param, const u64 max) { - hc_thread_mutex_lock (mux_dispatcher); + hc_thread_mutex_lock (opencl_ctx->mux_dispatcher); const u64 words_cur = data.words_cur; const u64 words_base = (data.limit == 0) ? data.words_base : MIN (data.limit, data.words_base); @@ -108,7 +106,7 @@ static uint get_work (hc_device_param_t *device_param, const u64 max) data.words_cur += work; - hc_thread_mutex_unlock (mux_dispatcher); + hc_thread_mutex_unlock (opencl_ctx->mux_dispatcher); return work; } @@ -130,11 +128,11 @@ void *thread_calc_stdin (void *p) while (opencl_ctx->run_thread_level1 == true) { - hc_thread_mutex_lock (mux_dispatcher); + hc_thread_mutex_lock (opencl_ctx->mux_dispatcher); if (feof (stdin) != 0) { - hc_thread_mutex_unlock (mux_dispatcher); + hc_thread_mutex_unlock (opencl_ctx->mux_dispatcher); break; } @@ -201,7 +199,7 @@ void *thread_calc_stdin (void *p) while (opencl_ctx->run_thread_level1 == false) break; } - hc_thread_mutex_unlock (mux_dispatcher); + hc_thread_mutex_unlock (opencl_ctx->mux_dispatcher); while (opencl_ctx->run_thread_level1 == false) break; @@ -257,7 +255,7 @@ void *thread_calc (void *p) { while (opencl_ctx->run_thread_level1 == true) { - const uint work = get_work (device_param, -1u); + const uint work = get_work (opencl_ctx, device_param, -1u); if (work == 0) break; @@ -371,7 +369,7 @@ void *thread_calc (void *p) while (max) { - const uint work = get_work (device_param, max); + const uint work = get_work (opencl_ctx, device_param, max); if (work == 0) break; diff --git a/src/hash_management.c b/src/hash_management.c index 96c4331e3..c00c5e7f5 100644 --- a/src/hash_management.c +++ b/src/hash_management.c @@ -17,12 +17,12 @@ #include "mpsp.h" #include "rp_cpu.h" #include "tuningdb.h" +#include "thread.h" #include "opencl.h" #include "hwmon.h" #include "restore.h" #include "hash_management.h" #include "filehandling.h" -#include "thread.h" #include "outfile.h" #include "potfile.h" #include "debugfile.h" diff --git a/src/hashcat.c b/src/hashcat.c index 5499bf2bc..7349d6f4b 100644 --- a/src/hashcat.c +++ b/src/hashcat.c @@ -45,11 +45,11 @@ #include "cpu_sha256.h" #include "filehandling.h" #include "tuningdb.h" +#include "thread.h" #include "opencl.h" #include "hwmon.h" #include "restore.h" #include "hash_management.h" -#include "thread.h" #include "locking.h" #include "rp_cpu.h" #include "rp_kernel_on_cpu.h" @@ -93,7 +93,6 @@ extern int SUPPRESS_OUTPUT; extern hc_thread_mutex_t mux_hwmon; extern hc_thread_mutex_t mux_display; extern hc_thread_mutex_t mux_counter; -extern hc_thread_mutex_t mux_dispatcher; extern void (*get_next_word_func) (char *, u32, u32 *, u32 *); @@ -186,7 +185,6 @@ int main (int argc, char **argv) int myargc = argc; char **myargv = argv; - hc_thread_mutex_init (mux_dispatcher); hc_thread_mutex_init (mux_counter); hc_thread_mutex_init (mux_display); hc_thread_mutex_init (mux_hwmon); @@ -5334,7 +5332,6 @@ int main (int argc, char **argv) // destroy others mutex - hc_thread_mutex_delete (mux_dispatcher); hc_thread_mutex_delete (mux_counter); hc_thread_mutex_delete (mux_display); hc_thread_mutex_delete (mux_hwmon); diff --git a/src/hlfmt.c b/src/hlfmt.c index ed6407742..2f5498191 100644 --- a/src/hlfmt.c +++ b/src/hlfmt.c @@ -19,11 +19,11 @@ #include "ext_nvml.h" #include "ext_xnvctrl.h" #include "tuningdb.h" +#include "thread.h" #include "opencl.h" #include "hwmon.h" #include "restore.h" #include "hash_management.h" -#include "thread.h" #include "filehandling.h" #include "rp_cpu.h" #include "inc_hash_constants.h" diff --git a/src/hwmon.c b/src/hwmon.c index 6cbfa84e0..14f855e23 100644 --- a/src/hwmon.c +++ b/src/hwmon.c @@ -17,11 +17,11 @@ #include "mpsp.h" #include "rp_cpu.h" #include "tuningdb.h" +#include "thread.h" #include "opencl.h" #include "hwmon.h" #include "restore.h" #include "hash_management.h" -#include "thread.h" #include "outfile.h" #include "potfile.h" #include "debugfile.h" diff --git a/src/logfile.c b/src/logfile.c index 20952016f..de2f12a1e 100644 --- a/src/logfile.c +++ b/src/logfile.c @@ -20,6 +20,7 @@ #include "rp_cpu.h" #include "mpsp.h" #include "tuningdb.h" +#include "thread.h" #include "opencl.h" #include "hwmon.h" #include "restore.h" diff --git a/src/monitor.c b/src/monitor.c index 39fe5d1d5..396602606 100644 --- a/src/monitor.c +++ b/src/monitor.c @@ -17,11 +17,11 @@ #include "mpsp.h" #include "rp_cpu.h" #include "tuningdb.h" +#include "thread.h" #include "opencl.h" #include "hwmon.h" #include "restore.h" #include "hash_management.h" -#include "thread.h" #include "outfile.h" #include "potfile.h" #include "debugfile.h" diff --git a/src/mpsp.c b/src/mpsp.c index 03c240b22..e53717033 100644 --- a/src/mpsp.c +++ b/src/mpsp.c @@ -21,11 +21,11 @@ #include "ext_xnvctrl.h" #include "filehandling.h" #include "tuningdb.h" +#include "thread.h" #include "opencl.h" #include "hwmon.h" #include "restore.h" #include "hash_management.h" -#include "thread.h" #include "mpsp.h" #include "rp_cpu.h" #include "outfile.h" diff --git a/src/opencl.c b/src/opencl.c index dff67a115..7adcd1efc 100644 --- a/src/opencl.c +++ b/src/opencl.c @@ -22,7 +22,6 @@ #include "hwmon.h" #include "restore.h" #include "hash_management.h" -#include "thread.h" #include "status.h" #include "stdout.h" #include "mpsp.h" @@ -1314,6 +1313,8 @@ int opencl_ctx_init (opencl_ctx_t *opencl_ctx, const char *opencl_platforms, con return 0; } + hc_thread_mutex_init (opencl_ctx->mux_dispatcher); + opencl_ctx->devices_status = STATUS_INIT; opencl_ctx->run_main_level1 = true; opencl_ctx->run_main_level2 = true; @@ -1499,6 +1500,8 @@ void opencl_ctx_destroy (opencl_ctx_t *opencl_ctx) myfree (opencl_ctx->platform_devices); + hc_thread_mutex_delete (opencl_ctx->mux_dispatcher); + myfree (opencl_ctx); } diff --git a/src/outfile_check.c b/src/outfile_check.c index 51aa5c074..041064b82 100644 --- a/src/outfile_check.c +++ b/src/outfile_check.c @@ -17,6 +17,7 @@ #include "mpsp.h" #include "rp_cpu.h" #include "tuningdb.h" +#include "thread.h" #include "opencl.h" #include "hwmon.h" #include "restore.h" @@ -29,7 +30,6 @@ #include "status.h" #include "convert.h" #include "shared.h" -#include "thread.h" #include "outfile_check.h" extern hc_global_data_t data; diff --git a/src/restore.c b/src/restore.c index b2a7a85f4..fd3d9b243 100644 --- a/src/restore.c +++ b/src/restore.c @@ -15,11 +15,11 @@ #include "ext_nvml.h" #include "ext_xnvctrl.h" #include "tuningdb.h" +#include "thread.h" #include "opencl.h" #include "hwmon.h" #include "restore.h" #include "hash_management.h" -#include "thread.h" #include "rp_cpu.h" #include "mpsp.h" #include "outfile.h" diff --git a/src/rp_cpu.c b/src/rp_cpu.c index 2a8c3fc5e..be1466ccd 100644 --- a/src/rp_cpu.c +++ b/src/rp_cpu.c @@ -20,11 +20,11 @@ #include "ext_xnvctrl.h" #include "convert.h" #include "tuningdb.h" +#include "thread.h" #include "opencl.h" #include "hwmon.h" #include "restore.h" #include "hash_management.h" -#include "thread.h" #include "rp_cpu.h" #include "terminal.h" #include "mpsp.h" diff --git a/src/status.c b/src/status.c index c0d90f1bd..900e60a44 100644 --- a/src/status.c +++ b/src/status.c @@ -15,11 +15,11 @@ #include "ext_nvml.h" #include "ext_xnvctrl.h" #include "tuningdb.h" +#include "thread.h" #include "opencl.h" #include "hwmon.h" #include "restore.h" #include "hash_management.h" -#include "thread.h" #include "rp_cpu.h" #include "terminal.h" #include "mpsp.h" diff --git a/src/stdout.c b/src/stdout.c index d64492921..a89b53c7a 100644 --- a/src/stdout.c +++ b/src/stdout.c @@ -17,11 +17,11 @@ #include "ext_nvml.h" #include "ext_xnvctrl.h" #include "tuningdb.h" +#include "thread.h" #include "opencl.h" #include "hwmon.h" #include "restore.h" #include "hash_management.h" -#include "thread.h" #include "locking.h" #include "rp_cpu.h" #include "rp_kernel_on_cpu.h" diff --git a/src/terminal.c b/src/terminal.c index e54ea3f63..b1c9bbb17 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -16,11 +16,11 @@ #include "mpsp.h" #include "rp_cpu.h" #include "tuningdb.h" +#include "thread.h" #include "opencl.h" #include "hwmon.h" #include "restore.h" #include "hash_management.h" -#include "thread.h" #include "outfile.h" #include "potfile.h" #include "debugfile.h" diff --git a/src/thread.c b/src/thread.c index 3089c5d90..39c6fa023 100644 --- a/src/thread.c +++ b/src/thread.c @@ -16,11 +16,11 @@ #include "ext_nvml.h" #include "ext_xnvctrl.h" #include "tuningdb.h" +#include "thread.h" #include "opencl.h" #include "hwmon.h" #include "restore.h" #include "hash_management.h" -#include "thread.h" #include "rp_cpu.h" #include "terminal.h" #include "mpsp.h" diff --git a/src/tuningdb.c b/src/tuningdb.c index 8346f6ac9..948dc8482 100644 --- a/src/tuningdb.c +++ b/src/tuningdb.c @@ -12,6 +12,7 @@ #include "filehandling.h" #include "ext_OpenCL.h" #include "tuningdb.h" +#include "thread.h" #include "opencl.h" #include "hash_management.h" diff --git a/src/weak_hash.c b/src/weak_hash.c index 3157a220e..8760daeb7 100644 --- a/src/weak_hash.c +++ b/src/weak_hash.c @@ -16,6 +16,7 @@ #include "mpsp.h" #include "rp_cpu.h" #include "tuningdb.h" +#include "thread.h" #include "opencl.h" #include "hwmon.h" #include "restore.h" diff --git a/src/wordlist.c b/src/wordlist.c index 4c539d358..af4548388 100644 --- a/src/wordlist.c +++ b/src/wordlist.c @@ -17,11 +17,11 @@ #include "ext_nvml.h" #include "ext_xnvctrl.h" #include "tuningdb.h" +#include "thread.h" #include "opencl.h" #include "hwmon.h" #include "restore.h" #include "hash_management.h" -#include "thread.h" #include "locking.h" #include "rp_cpu.h" #include "rp_kernel_on_cpu.h"