3 * Copyright (c) 2016 Tino Reichardt
6 * This source code is licensed under the BSD-style license found in the
7 * LICENSE file in the root directory of this source tree. An additional grant
8 * of patent rights can be found in the PATENTS file in the same directory.
10 * You can contact the author at:
11 * - zstdmt source repository: https://github.com/mcmilk/zstdmt
15 * This file will hold wrapper for systems, which do not support pthreads
18 /* When ZSTD_MULTITHREAD is not defined, this file would become an empty translation unit.
19 * Include some ISO C header code to prevent this and portably avoid related warnings.
20 * (Visual C++: C4206 / GCC: -Wpedantic / Clang: -Wempty-translation-unit)
25 #if defined(ZSTD_MULTITHREAD) && defined(_WIN32)
28 * Windows minimalist Pthread Wrapper, based on :
29 * http://www.cse.wustl.edu/~schmidt/win32-cv-1.html
33 /* === Dependencies === */
36 #include "threading.h"
39 /* === Implementation === */
41 static unsigned __stdcall worker(void *arg)
43 pthread_t* const thread = (pthread_t*) arg;
44 thread->arg = thread->start_routine(thread->arg);
48 int pthread_create(pthread_t* thread, const void* unused,
49 void* (*start_routine) (void*), void* arg)
53 thread->start_routine = start_routine;
54 thread->handle = (HANDLE) _beginthreadex(NULL, 0, worker, thread, 0, NULL);
62 int _pthread_join(pthread_t * thread, void **value_ptr)
66 if (!thread->handle) return 0;
68 result = WaitForSingleObject(thread->handle, INFINITE);
71 if (value_ptr) *value_ptr = thread->arg;
76 return GetLastError();
80 #endif /* ZSTD_MULTITHREAD */