comparison contrib/python-zstandard/zstd/common/threading.c @ 37495:b1fb341d8a61

zstandard: vendor python-zstandard 0.9.0 This was just released. It features a number of goodies. More info at https://gregoryszorc.com/blog/2018/04/09/release-of-python-zstandard-0.9/. The clang-format ignore list was updated to reflect the new source of files. The project contains a vendored copy of zstandard 1.3.4. The old version was 1.1.3. One of the changes between those versions is that zstandard is now dual licensed BSD + GPLv2 and the patent rights grant has been removed. Good riddance. The API should be backwards compatible. So no changes in core should be needed. However, there were a number of changes in the library that we'll want to adapt to. Those will be addressed in subsequent commits. Differential Revision: https://phab.mercurial-scm.org/D3198
author Gregory Szorc <gregory.szorc@gmail.com>
date Mon, 09 Apr 2018 10:13:29 -0700
parents c32454d69b85
children 69de49c4e39c
comparison
equal deleted inserted replaced
37494:1ce7a55b09d1 37495:b1fb341d8a61
1
2 /** 1 /**
3 * Copyright (c) 2016 Tino Reichardt 2 * Copyright (c) 2016 Tino Reichardt
4 * All rights reserved. 3 * All rights reserved.
5 * 4 *
6 * This source code is licensed under the BSD-style license found in the 5 * This source code is licensed under both the BSD-style license (found in the
7 * LICENSE file in the root directory of this source tree. An additional grant 6 * LICENSE file in the root directory of this source tree) and the GPLv2 (found
8 * of patent rights can be found in the PATENTS file in the same directory. 7 * in the COPYING file in the root directory of this source tree).
9 * 8 *
10 * You can contact the author at: 9 * You can contact the author at:
11 * - zstdmt source repository: https://github.com/mcmilk/zstdmt 10 * - zstdmt source repository: https://github.com/mcmilk/zstdmt
12 */ 11 */
13 12
14 /** 13 /**
15 * This file will hold wrapper for systems, which do not support pthreads 14 * This file will hold wrapper for systems, which do not support pthreads
16 */ 15 */
17 16
18 /* ====== Compiler specifics ====== */ 17 /* create fake symbol to avoid empty trnaslation unit warning */
19 #if defined(_MSC_VER) 18 int g_ZSTD_threading_useles_symbol;
20 # pragma warning(disable : 4206) /* disable: C4206: translation unit is empty (when ZSTD_MULTITHREAD is not defined) */
21 #endif
22
23 19
24 #if defined(ZSTD_MULTITHREAD) && defined(_WIN32) 20 #if defined(ZSTD_MULTITHREAD) && defined(_WIN32)
25 21
26 /** 22 /**
27 * Windows minimalist Pthread Wrapper, based on : 23 * Windows minimalist Pthread Wrapper, based on :
37 33
38 /* === Implementation === */ 34 /* === Implementation === */
39 35
40 static unsigned __stdcall worker(void *arg) 36 static unsigned __stdcall worker(void *arg)
41 { 37 {
42 pthread_t* const thread = (pthread_t*) arg; 38 ZSTD_pthread_t* const thread = (ZSTD_pthread_t*) arg;
43 thread->arg = thread->start_routine(thread->arg); 39 thread->arg = thread->start_routine(thread->arg);
44 return 0; 40 return 0;
45 } 41 }
46 42
47 int pthread_create(pthread_t* thread, const void* unused, 43 int ZSTD_pthread_create(ZSTD_pthread_t* thread, const void* unused,
48 void* (*start_routine) (void*), void* arg) 44 void* (*start_routine) (void*), void* arg)
49 { 45 {
50 (void)unused; 46 (void)unused;
51 thread->arg = arg; 47 thread->arg = arg;
52 thread->start_routine = start_routine; 48 thread->start_routine = start_routine;
56 return errno; 52 return errno;
57 else 53 else
58 return 0; 54 return 0;
59 } 55 }
60 56
61 int _pthread_join(pthread_t * thread, void **value_ptr) 57 int ZSTD_pthread_join(ZSTD_pthread_t thread, void **value_ptr)
62 { 58 {
63 DWORD result; 59 DWORD result;
64 60
65 if (!thread->handle) return 0; 61 if (!thread.handle) return 0;
66 62
67 result = WaitForSingleObject(thread->handle, INFINITE); 63 result = WaitForSingleObject(thread.handle, INFINITE);
68 switch (result) { 64 switch (result) {
69 case WAIT_OBJECT_0: 65 case WAIT_OBJECT_0:
70 if (value_ptr) *value_ptr = thread->arg; 66 if (value_ptr) *value_ptr = thread.arg;
71 return 0; 67 return 0;
72 case WAIT_ABANDONED: 68 case WAIT_ABANDONED:
73 return EINVAL; 69 return EINVAL;
74 default: 70 default:
75 return GetLastError(); 71 return GetLastError();