diff options
author | Brad King <brad.king@kitware.com> | 2019-03-13 14:46:32 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2019-03-13 14:46:32 (GMT) |
commit | f92b4b52ebb335ce540966d7f198df3878f6f46f (patch) | |
tree | 4fe887bedbdff138072bfa6e0d1217b0756b2155 /Utilities/cmzstd/lib/common/threading.c | |
parent | 9337cbfccab0b7a0984b837d71ff59543acb574d (diff) | |
parent | fbaf65639ada9f3dc58337bf86c1cc036bc1694f (diff) | |
download | CMake-f92b4b52ebb335ce540966d7f198df3878f6f46f.zip CMake-f92b4b52ebb335ce540966d7f198df3878f6f46f.tar.gz CMake-f92b4b52ebb335ce540966d7f198df3878f6f46f.tar.bz2 |
Merge branch 'upstream-zstd' into import-zstd
* upstream-zstd:
zstd 2018-12-27 (470344d3)
Diffstat (limited to 'Utilities/cmzstd/lib/common/threading.c')
-rw-r--r-- | Utilities/cmzstd/lib/common/threading.c | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/Utilities/cmzstd/lib/common/threading.c b/Utilities/cmzstd/lib/common/threading.c new file mode 100644 index 0000000..8be8c8d --- /dev/null +++ b/Utilities/cmzstd/lib/common/threading.c @@ -0,0 +1,75 @@ +/** + * Copyright (c) 2016 Tino Reichardt + * All rights reserved. + * + * This source code is licensed under both the BSD-style license (found in the + * LICENSE file in the root directory of this source tree) and the GPLv2 (found + * in the COPYING file in the root directory of this source tree). + * + * You can contact the author at: + * - zstdmt source repository: https://github.com/mcmilk/zstdmt + */ + +/** + * This file will hold wrapper for systems, which do not support pthreads + */ + +/* create fake symbol to avoid empty trnaslation unit warning */ +int g_ZSTD_threading_useles_symbol; + +#if defined(ZSTD_MULTITHREAD) && defined(_WIN32) + +/** + * Windows minimalist Pthread Wrapper, based on : + * http://www.cse.wustl.edu/~schmidt/win32-cv-1.html + */ + + +/* === Dependencies === */ +#include <process.h> +#include <errno.h> +#include "threading.h" + + +/* === Implementation === */ + +static unsigned __stdcall worker(void *arg) +{ + ZSTD_pthread_t* const thread = (ZSTD_pthread_t*) arg; + thread->arg = thread->start_routine(thread->arg); + return 0; +} + +int ZSTD_pthread_create(ZSTD_pthread_t* thread, const void* unused, + void* (*start_routine) (void*), void* arg) +{ + (void)unused; + thread->arg = arg; + thread->start_routine = start_routine; + thread->handle = (HANDLE) _beginthreadex(NULL, 0, worker, thread, 0, NULL); + + if (!thread->handle) + return errno; + else + return 0; +} + +int ZSTD_pthread_join(ZSTD_pthread_t thread, void **value_ptr) +{ + DWORD result; + + if (!thread.handle) return 0; + + result = WaitForSingleObject(thread.handle, INFINITE); + switch (result) { + case WAIT_OBJECT_0: + if (value_ptr) *value_ptr = thread.arg; + return 0; + case WAIT_ABANDONED: + return EINVAL; + default: + return GetLastError(); + } +} + +#endif /* ZSTD_MULTITHREAD */ |