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() {
|
stack_context allocate_stack() {
|
||||||
std::lock_guard<std::mutex> l{p_lock};
|
if constexpr(!SA::is_thread_safe) {
|
||||||
return p_stacks.allocate();
|
std::lock_guard<std::mutex> l{p_lock};
|
||||||
|
return p_stacks.allocate();
|
||||||
|
} else {
|
||||||
|
return p_stacks.allocate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void deallocate_stack(stack_context &st) noexcept {
|
void deallocate_stack(stack_context &st) noexcept {
|
||||||
std::lock_guard<std::mutex> l{p_lock};
|
if constexpr(!SA::is_thread_safe) {
|
||||||
p_stacks.deallocate(st);
|
std::lock_guard<std::mutex> l{p_lock};
|
||||||
|
p_stacks.deallocate(st);
|
||||||
|
} else {
|
||||||
|
p_stacks.deallocate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void reserve_stacks(size_t n) {
|
void reserve_stacks(size_t n) {
|
||||||
std::lock_guard<std::mutex> l{p_lock};
|
if constexpr(!SA::is_thread_safe) {
|
||||||
p_stacks.reserve(n);
|
std::lock_guard<std::mutex> l{p_lock};
|
||||||
|
p_stacks.reserve(n);
|
||||||
|
} else {
|
||||||
|
p_stacks.reserve(n);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -509,18 +521,30 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
stack_context allocate_stack() {
|
stack_context allocate_stack() {
|
||||||
std::lock_guard<std::mutex> l{p_lock};
|
if constexpr(!SA::is_thread_safe) {
|
||||||
return p_stacks.allocate();
|
std::lock_guard<std::mutex> l{p_lock};
|
||||||
|
return p_stacks.allocate();
|
||||||
|
} else {
|
||||||
|
return p_stacks.allocate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void deallocate_stack(stack_context &st) noexcept {
|
void deallocate_stack(stack_context &st) noexcept {
|
||||||
std::lock_guard<std::mutex> l{p_lock};
|
if constexpr(!SA::is_thread_safe) {
|
||||||
p_stacks.deallocate(st);
|
std::lock_guard<std::mutex> l{p_lock};
|
||||||
|
p_stacks.deallocate(st);
|
||||||
|
} else {
|
||||||
|
p_stacks.deallocate();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void reserve_stacks(size_t n) {
|
void reserve_stacks(size_t n) {
|
||||||
std::lock_guard<std::mutex> l{p_lock};
|
if constexpr(!SA::is_thread_safe) {
|
||||||
p_stacks.reserve(n);
|
std::lock_guard<std::mutex> l{p_lock};
|
||||||
|
p_stacks.reserve(n);
|
||||||
|
} else {
|
||||||
|
p_stacks.reserve(n);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -50,6 +50,7 @@ template<typename TR, bool Protected>
|
||||||
struct basic_fixedsize_stack {
|
struct basic_fixedsize_stack {
|
||||||
using traits_type = TR;
|
using traits_type = TR;
|
||||||
using allocator_type = basic_fixedsize_stack;
|
using allocator_type = basic_fixedsize_stack;
|
||||||
|
static constexpr bool is_thread_safe = true;
|
||||||
|
|
||||||
basic_fixedsize_stack(size_t ss = TR::default_size()) noexcept:
|
basic_fixedsize_stack(size_t ss = TR::default_size()) noexcept:
|
||||||
p_size(
|
p_size(
|
||||||
|
@ -127,6 +128,7 @@ public:
|
||||||
|
|
||||||
using traits_type = TR;
|
using traits_type = TR;
|
||||||
using allocator_type = allocator;
|
using allocator_type = allocator;
|
||||||
|
static constexpr bool is_thread_safe = false;
|
||||||
|
|
||||||
basic_stack_pool(
|
basic_stack_pool(
|
||||||
size_t ss = TR::default_size(), size_t cs = DEFAULT_CHUNK_SIZE
|
size_t ss = TR::default_size(), size_t cs = DEFAULT_CHUNK_SIZE
|
||||||
|
|
Loading…
Reference in a new issue