Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pr.static assert def #4

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions thread_pool/fixed_function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,11 @@ class FixedFunction<R(ARGS...), STORAGE_SIZE> {
{
typedef typename std::remove_reference<FUNC>::type unref_type;

#if THREAD_POOL_FIXED_FUNCTION_SIZE_CONSTRAINT
static_assert(sizeof(unref_type) < STORAGE_SIZE,
"functional object doesn't fit into internal storage");
#endif

static_assert(std::is_move_constructible<unref_type>::value, "Should be of movable type");

m_method_ptr = [](void *object_ptr, func_ptr_type, ARGS... args) -> R {
Expand Down
12 changes: 11 additions & 1 deletion thread_pool/worker.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
#ifndef WORKER_HPP
#define WORKER_HPP

// http://stackoverflow.com/a/25393790/5724090
// Static/global variable exists in a per-thread context (thread local storage).
#if defined (__GNUC__)
#define ATTRIBUTE_TLS __thread
#elif defined (_MSC_VER)
#define ATTRIBUTE_TLS __declspec(thread)
#else // !__GNUC__ && !_MSC_VER
#error "Define a thread local storage qualifier for your compiler/platform!"
#endif

#include <fixed_function.hpp>
#include <mpsc_bounded_queue.hpp>
#include <atomic>
Expand Down Expand Up @@ -78,7 +88,7 @@ class Worker {
namespace detail {
inline size_t * thread_id()
{
static thread_local size_t tss_id = -1u;
static ATTRIBUTE_TLS size_t tss_id = -1u;
return &tss_id;
}
}
Expand Down