2016-12-31 15:32:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Copyright (c) 2016 Tino Reichardt
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
|
|
|
* You can contact the author at:
|
|
|
|
* - zstdmt source repository: https://github.com/mcmilk/zstdmt
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef THREADING_H_938743
|
|
|
|
#define THREADING_H_938743
|
|
|
|
|
|
|
|
#if defined (__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2017-01-19 22:05:07 +00:00
|
|
|
#if defined(ZSTD_MULTITHREAD) && defined(_WIN32)
|
2016-12-31 15:32:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Windows minimalist Pthread Wrapper, based on :
|
|
|
|
* http://www.cse.wustl.edu/~schmidt/win32-cv-1.html
|
|
|
|
*/
|
2017-01-01 00:10:29 +00:00
|
|
|
#ifdef WINVER
|
|
|
|
# undef WINVER
|
|
|
|
#endif
|
|
|
|
#define WINVER 0x0600
|
|
|
|
|
|
|
|
#ifdef _WIN32_WINNT
|
|
|
|
# undef _WIN32_WINNT
|
|
|
|
#endif
|
|
|
|
#define _WIN32_WINNT 0x0600
|
2016-12-31 15:32:19 +00:00
|
|
|
|
|
|
|
#ifndef WIN32_LEAN_AND_MEAN
|
|
|
|
# define WIN32_LEAN_AND_MEAN
|
|
|
|
#endif
|
2017-01-01 00:10:29 +00:00
|
|
|
|
2016-12-31 15:32:19 +00:00
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
/* mutex */
|
|
|
|
#define pthread_mutex_t CRITICAL_SECTION
|
|
|
|
#define pthread_mutex_init(a,b) InitializeCriticalSection((a))
|
|
|
|
#define pthread_mutex_destroy(a) DeleteCriticalSection((a))
|
2017-01-01 00:10:29 +00:00
|
|
|
#define pthread_mutex_lock(a) EnterCriticalSection((a))
|
|
|
|
#define pthread_mutex_unlock(a) LeaveCriticalSection((a))
|
|
|
|
|
|
|
|
/* condition variable */
|
|
|
|
#define pthread_cond_t CONDITION_VARIABLE
|
|
|
|
#define pthread_cond_init(a, b) InitializeConditionVariable((a))
|
|
|
|
#define pthread_cond_destroy(a) /* No delete */
|
|
|
|
#define pthread_cond_wait(a, b) SleepConditionVariableCS((a), (b), INFINITE)
|
|
|
|
#define pthread_cond_signal(a) WakeConditionVariable((a))
|
|
|
|
#define pthread_cond_broadcast(a) WakeAllConditionVariable((a))
|
2016-12-31 15:32:19 +00:00
|
|
|
|
|
|
|
/* pthread_create() and pthread_join() */
|
|
|
|
typedef struct {
|
|
|
|
HANDLE handle;
|
|
|
|
void* (*start_routine)(void*);
|
2017-01-01 00:10:29 +00:00
|
|
|
void* arg;
|
2016-12-31 15:32:19 +00:00
|
|
|
} pthread_t;
|
|
|
|
|
|
|
|
int pthread_create(pthread_t* thread, const void* unused,
|
|
|
|
void* (*start_routine) (void*), void* arg);
|
|
|
|
|
|
|
|
#define pthread_join(a, b) _pthread_join(&(a), (b))
|
|
|
|
int _pthread_join(pthread_t* thread, void** value_ptr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* add here more wrappers as required
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2017-02-20 20:08:59 +00:00
|
|
|
#elif defined(ZSTD_MULTITHREAD) /* posix assumed ; need a better detection method */
|
2016-12-31 15:32:19 +00:00
|
|
|
/* === POSIX Systems === */
|
|
|
|
# include <pthread.h>
|
|
|
|
|
2017-01-19 22:05:07 +00:00
|
|
|
#else /* ZSTD_MULTITHREAD not defined */
|
2016-12-31 15:32:19 +00:00
|
|
|
/* No multithreading support */
|
|
|
|
|
2017-01-02 00:11:55 +00:00
|
|
|
#define pthread_mutex_t int /* #define rather than typedef, as sometimes pthread support is implicit, resulting in duplicated symbols */
|
2016-12-31 15:32:19 +00:00
|
|
|
#define pthread_mutex_init(a,b)
|
|
|
|
#define pthread_mutex_destroy(a)
|
|
|
|
#define pthread_mutex_lock(a)
|
|
|
|
#define pthread_mutex_unlock(a)
|
|
|
|
|
2017-01-02 00:11:55 +00:00
|
|
|
#define pthread_cond_t int
|
2017-01-01 00:10:29 +00:00
|
|
|
#define pthread_cond_init(a,b)
|
|
|
|
#define pthread_cond_destroy(a)
|
|
|
|
#define pthread_cond_wait(a,b)
|
|
|
|
#define pthread_cond_signal(a)
|
|
|
|
#define pthread_cond_broadcast(a)
|
|
|
|
|
2016-12-31 15:32:19 +00:00
|
|
|
/* do not use pthread_t */
|
|
|
|
|
2017-01-19 22:05:07 +00:00
|
|
|
#endif /* ZSTD_MULTITHREAD */
|
2016-12-31 15:32:19 +00:00
|
|
|
|
|
|
|
#if defined (__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* THREADING_H_938743 */
|