2 * Copyright (c) 2016 Tino Reichardt
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree. An additional grant
7 * of patent rights can be found in the PATENTS file in the same directory.
9 * You can contact the author at:
10 * - zstdmt source repository: https://github.com/mcmilk/zstdmt
14 * This file will hold wrapper for systems, which do not support pthreads
17 /* When ZSTD_MULTITHREAD is not defined, this file would become an empty translation unit.
18 * Include some ISO C header code to prevent this and portably avoid related warnings.
19 * (Visual C++: C4206 / GCC: -Wpedantic / Clang: -Wempty-translation-unit)
24 #if defined(ZSTD_MULTITHREAD) && defined(_WIN32)
27 * Windows minimalist Pthread Wrapper, based on :
28 * http://www.cse.wustl.edu/~schmidt/win32-cv-1.html
32 /* === Dependencies === */
35 #include "threading.h"
38 /* === Implementation === */
40 static unsigned __stdcall worker(void *arg)
42 pthread_t* const thread = (pthread_t*) arg;
43 thread->arg = thread->start_routine(thread->arg);
47 int pthread_create(pthread_t* thread, const void* unused,
48 void* (*start_routine) (void*), void* arg)
52 thread->start_routine = start_routine;
53 thread->handle = (HANDLE) _beginthreadex(NULL, 0, worker, thread, 0, NULL);
61 int _pthread_join(pthread_t * thread, void **value_ptr)
65 if (!thread->handle) return 0;
67 result = WaitForSingleObject(thread->handle, INFINITE);
70 if (value_ptr) *value_ptr = thread->arg;
75 return GetLastError();
79 #endif /* ZSTD_MULTITHREAD */