1
0
mirror of https://github.com/hashcat/hashcat.git synced 2024-11-22 16:18:09 +00:00

Add sempaphore macros for later use

Switch from CriticalSection to regular Mutex on windows
This commit is contained in:
jsteube 2018-08-16 14:57:10 +02:00
parent c5fb316912
commit 6092308324
2 changed files with 27 additions and 5 deletions

View File

@ -20,23 +20,42 @@
#define hc_thread_create(t,f,a) t = CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE) &f, a, 0, NULL) #define hc_thread_create(t,f,a) t = CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE) &f, a, 0, NULL)
#define hc_thread_wait(n,a) for (u32 i = 0; i < n; i++) WaitForSingleObject ((a)[i], INFINITE) #define hc_thread_wait(n,a) for (u32 i = 0; i < n; i++) WaitForSingleObject ((a)[i], INFINITE)
#define hc_thread_exit(t) ExitThread (t) #define hc_thread_exit(t) ExitThread (t)
#define hc_thread_detach(t) CloseHandle (t)
/*
#define hc_thread_mutex_lock(m) EnterCriticalSection (&m) #define hc_thread_mutex_lock(m) EnterCriticalSection (&m)
#define hc_thread_mutex_unlock(m) LeaveCriticalSection (&m) #define hc_thread_mutex_unlock(m) LeaveCriticalSection (&m)
#define hc_thread_mutex_init(m) InitializeCriticalSection (&m) #define hc_thread_mutex_init(m) InitializeCriticalSection (&m)
#define hc_thread_mutex_delete(m) DeleteCriticalSection (&m) #define hc_thread_mutex_delete(m) DeleteCriticalSection (&m)
*/
#define hc_thread_mutex_init(m) m = CreateMutex (NULL, FALSE, NULL)
#define hc_thread_mutex_lock(m) WaitForSingleObject (m, INFINITE)
#define hc_thread_mutex_unlock(m) ReleaseMutex (m)
#define hc_thread_mutex_delete(m) CloseHandle (m)
#define hc_thread_sem_init(s) s = CreateSemaphore (NULL, 0, INT_MAX, NULL)
#define hc_thread_sem_post(s) ReleaseSemaphore (s, 1, NULL)
#define hc_thread_sem_wait(s) WaitForSingleObject (s, INFINITE)
#define hc_thread_sem_close(s) CloseHandle (s)
#else #else
#define hc_thread_create(t,f,a) pthread_create (&t, NULL, f, a) #define hc_thread_create(t,f,a) pthread_create (&t, NULL, f, a)
#define hc_thread_wait(n,a) for (u32 i = 0; i < n; i++) pthread_join ((a)[i], NULL) #define hc_thread_wait(n,a) for (u32 i = 0; i < n; i++) pthread_join ((a)[i], NULL)
#define hc_thread_exit(t) pthread_exit (&t) #define hc_thread_exit(t) pthread_exit (&t)
#define hc_thread_detach(t) pthread_detach (t)
#define hc_thread_mutex_init(m) pthread_mutex_init (&m, NULL)
#define hc_thread_mutex_lock(m) pthread_mutex_lock (&m) #define hc_thread_mutex_lock(m) pthread_mutex_lock (&m)
#define hc_thread_mutex_unlock(m) pthread_mutex_unlock (&m) #define hc_thread_mutex_unlock(m) pthread_mutex_unlock (&m)
#define hc_thread_mutex_init(m) pthread_mutex_init (&m, NULL)
#define hc_thread_mutex_delete(m) pthread_mutex_destroy (&m) #define hc_thread_mutex_delete(m) pthread_mutex_destroy (&m)
#define hc_thread_sem_init(s) sem_init (&s, 0, 0)
#define hc_thread_sem_post(s) sem_post (&s)
#define hc_thread_sem_wait(s) sem_wait (&s)
#define hc_thread_sem_close(s) sem_close (&s)
#endif #endif
/* /*

View File

@ -57,14 +57,17 @@ typedef struct timespec hc_timer_t;
#if defined (_POSIX) #if defined (_POSIX)
#include <pthread.h> #include <pthread.h>
#include <semaphore.h>
#endif #endif
#if defined (_WIN) #if defined (_WIN)
typedef HANDLE hc_thread_t; typedef HANDLE hc_thread_t;
typedef CRITICAL_SECTION hc_thread_mutex_t; typedef HANDLE hc_thread_mutex_t;
typedef HANDLE hc_thread_semaphore_t;
#else #else
typedef pthread_t hc_thread_t; typedef pthread_t hc_thread_t;
typedef pthread_mutex_t hc_thread_mutex_t; typedef pthread_mutex_t hc_thread_mutex_t;
typedef sem_t hc_thread_semaphore_t;
#endif #endif
// enums // enums