diff options
author | Marat Dukhan <maratek@google.com> | 2020-04-01 17:08:30 -0700 |
---|---|---|
committer | Marat Dukhan <maratek@google.com> | 2020-04-01 17:08:30 -0700 |
commit | fc793bc6d7eab64756df79971556594bf4ab145b (patch) | |
tree | 669f93c06ca276279aa3acb6b91edb8029e5f5a7 /src/threadpool-common.h | |
parent | 5b41aa6060588e26fd25ace6dc4afccfd4793997 (diff) | |
download | pthreadpool-fc793bc6d7eab64756df79971556594bf4ab145b.tar.gz |
Refactor pthreadpool implementation
Split implementation into two types of components:
- Components dependent on threading API
- Portable components
Diffstat (limited to 'src/threadpool-common.h')
-rw-r--r-- | src/threadpool-common.h | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/threadpool-common.h b/src/threadpool-common.h new file mode 100644 index 0000000..1a18c60 --- /dev/null +++ b/src/threadpool-common.h @@ -0,0 +1,44 @@ +#pragma once + +#ifndef PTHREADPOOL_USE_CPUINFO + #define PTHREADPOOL_USE_CPUINFO 0 +#endif + +#ifndef PTHREADPOOL_USE_FUTEX + #if defined(__linux__) + #define PTHREADPOOL_USE_FUTEX 1 + #elif defined(__EMSCRIPTEN__) + #define PTHREADPOOL_USE_FUTEX 1 + #else + #define PTHREADPOOL_USE_FUTEX 0 + #endif +#endif + +/* Number of iterations in spin-wait loop before going into futex/condvar wait */ +#define PTHREADPOOL_SPIN_WAIT_ITERATIONS 1000000 + +#define PTHREADPOOL_CACHELINE_SIZE 64 +#define PTHREADPOOL_CACHELINE_ALIGNED __attribute__((__aligned__(PTHREADPOOL_CACHELINE_SIZE))) + +#if defined(__clang__) + #if __has_extension(c_static_assert) || __has_feature(c_static_assert) + #define PTHREADPOOL_STATIC_ASSERT(predicate, message) _Static_assert((predicate), message) + #else + #define PTHREADPOOL_STATIC_ASSERT(predicate, message) + #endif +#elif defined(__GNUC__) && ((__GNUC__ > 4) || (__GNUC__ == 4) && (__GNUC_MINOR__ >= 6)) + /* Static assert is supported by gcc >= 4.6 */ + #define PTHREADPOOL_STATIC_ASSERT(predicate, message) _Static_assert((predicate), message) +#else + #define PTHREADPOOL_STATIC_ASSERT(predicate, message) +#endif + +#ifndef PTHREADPOOL_INTERNAL + #if defined(__ELF__) + #define PTHREADPOOL_INTERNAL __attribute__((__visibility__("internal"))) + #elif defined(__MACH__) + #define PTHREADPOOL_INTERNAL __attribute__((__visibility__("hidden"))) + #else + #define PTHREADPOOL_INTERNAL + #endif +#endif |