only lock for stack manipulation with potentially unsafe allocators

master
Daniel Kolesa 2017-03-25 15:13:21 +01:00
parent 9fc3d70fe3
commit b02521ac19
2 changed files with 38 additions and 12 deletions

View File

@ -148,18 +148,30 @@ struct basic_thread_scheduler: scheduler {
}
stack_context allocate_stack() {
std::lock_guard<std::mutex> l{p_lock};
return p_stacks.allocate();
if constexpr(!SA::is_thread_safe) {
std::lock_guard<std::mutex> l{p_lock};
return p_stacks.allocate();
} else {
return p_stacks.allocate();
}
}
void deallocate_stack(stack_context &st) noexcept {
std::lock_guard<std::mutex> l{p_lock};
p_stacks.deallocate(st);
if constexpr(!SA::is_thread_safe) {
std::lock_guard<std::mutex> l{p_lock};
p_stacks.deallocate(st);
} else {
p_stacks.deallocate();
}
}
void reserve_stacks(size_t n) {
std::lock_guard<std::mutex> l{p_lock};
p_stacks.reserve(n);
if constexpr(!SA::is_thread_safe) {
std::lock_guard<std::mutex> l{p_lock};
p_stacks.reserve(n);
} else {
p_stacks.reserve(n);
}
}
private:
@ -509,18 +521,30 @@ public:
}
stack_context allocate_stack() {
std::lock_guard<std::mutex> l{p_lock};
return p_stacks.allocate();
if constexpr(!SA::is_thread_safe) {
std::lock_guard<std::mutex> l{p_lock};
return p_stacks.allocate();
} else {
return p_stacks.allocate();
}
}
void deallocate_stack(stack_context &st) noexcept {
std::lock_guard<std::mutex> l{p_lock};
p_stacks.deallocate(st);
if constexpr(!SA::is_thread_safe) {
std::lock_guard<std::mutex> l{p_lock};
p_stacks.deallocate(st);
} else {
p_stacks.deallocate();
}
}
void reserve_stacks(size_t n) {
std::lock_guard<std::mutex> l{p_lock};
p_stacks.reserve(n);
if constexpr(!SA::is_thread_safe) {
std::lock_guard<std::mutex> l{p_lock};
p_stacks.reserve(n);
} else {
p_stacks.reserve(n);
}
}
private:

View File

@ -50,6 +50,7 @@ template<typename TR, bool Protected>
struct basic_fixedsize_stack {
using traits_type = TR;
using allocator_type = basic_fixedsize_stack;
static constexpr bool is_thread_safe = true;
basic_fixedsize_stack(size_t ss = TR::default_size()) noexcept:
p_size(
@ -127,6 +128,7 @@ public:
using traits_type = TR;
using allocator_type = allocator;
static constexpr bool is_thread_safe = false;
basic_stack_pool(
size_t ss = TR::default_size(), size_t cs = DEFAULT_CHUNK_SIZE