23#if defined(ZSTD_MULTITHREAD) && defined(_WIN32)
38 void* (*start_routine)(
void*);
43} ZSTD_thread_params_t;
45static unsigned __stdcall worker(
void *arg)
47 void* (*start_routine)(
void*);
54 ZSTD_thread_params_t* thread_param = (ZSTD_thread_params_t*)arg;
55 thread_arg = thread_param->arg;
56 start_routine = thread_param->start_routine;
60 thread_param->initialized = 1;
65 start_routine(thread_arg);
70int ZSTD_pthread_create(ZSTD_pthread_t* thread,
const void* unused,
71 void* (*start_routine) (
void*),
void* arg)
73 ZSTD_thread_params_t thread_param;
76 if (thread==NULL)
return -1;
79 thread_param.start_routine = start_routine;
80 thread_param.arg = arg;
81 thread_param.initialized = 0;
95 *thread = (HANDLE)_beginthreadex(NULL, 0, worker, &thread_param, 0, NULL);
104 while(!thread_param.initialized) {
114int ZSTD_pthread_join(ZSTD_pthread_t thread)
118 if (!thread)
return 0;
120 result = WaitForSingleObject(thread, INFINITE);
129 return GetLastError();
135#if defined(ZSTD_MULTITHREAD) && DEBUGLEVEL >= 1 && !defined(_WIN32)
137#define ZSTD_DEPS_NEED_MALLOC
143 *mutex = (pthread_mutex_t*)ZSTD_malloc(
sizeof(pthread_mutex_t));
146 return pthread_mutex_init(*mutex, attr);
155 int const ret = pthread_mutex_destroy(*mutex);
164 *cond = (pthread_cond_t*)ZSTD_malloc(
sizeof(pthread_cond_t));
167 return pthread_cond_init(*cond, attr);
176 int const ret = pthread_cond_destroy(*cond);
#define assert(condition)
int g_ZSTD_threading_useless_symbol
#define ZSTD_pthread_mutex_init(a, b)
#define ZSTD_pthread_mutex_unlock(a)
#define ZSTD_pthread_cond_signal(a)
#define ZSTD_pthread_cond_wait(a, b)
#define ZSTD_pthread_mutex_lock(a)
#define ZSTD_pthread_mutex_destroy(a)
#define ZSTD_pthread_cond_init(a, b)
#define ZSTD_pthread_cond_destroy(a)