forked from OctaForge/libostd
only lock for stack manipulation with potentially unsafe allocators
This commit is contained in:
parent
9fc3d70fe3
commit
b02521ac19
|
@ -148,18 +148,30 @@ struct basic_thread_scheduler: scheduler {
|
|||
}
|
||||
|
||||
stack_context allocate_stack() {
|
||||
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 {
|
||||
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) {
|
||||
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() {
|
||||
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 {
|
||||
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) {
|
||||
if constexpr(!SA::is_thread_safe) {
|
||||
std::lock_guard<std::mutex> l{p_lock};
|
||||
p_stacks.reserve(n);
|
||||
} else {
|
||||
p_stacks.reserve(n);
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue