Commit d2eff7da by FritzFlorian

Use only placement new on pre-allocated memory. This makes sure that we have to…

Use only placement new on pre-allocated memory. This makes sure that we have to have no assumptions on the inital state of the memory region.
parent d7107d27
Pipeline #1131 failed with stages
in 28 seconds
...@@ -32,13 +32,13 @@ namespace pls { ...@@ -32,13 +32,13 @@ namespace pls {
template<typename T> template<typename T>
T* push(const T& object) { T* push(const T& object) {
// Copy-Construct into desired memory location // Placement new into desired memory location
return new (push<T>())T(object); return new ((void*)push<T>())T(object);
} }
template<typename T> template<typename T>
T* push() { void* push() {
T* result = reinterpret_cast<T*>(head_); void* result = reinterpret_cast<T*>(head_);
// Move head to next aligned position after new object // Move head to next aligned position after new object
head_ = next_alignment(head_ + sizeof(T)); head_ = next_alignment(head_ + sizeof(T));
......
...@@ -32,23 +32,6 @@ namespace pls { ...@@ -32,23 +32,6 @@ namespace pls {
current_task_{nullptr}, current_task_{nullptr},
task_stack_{task_stack}, task_stack_{task_stack},
id_{id} {} id_{id} {}
thread_state(const thread_state& other):
scheduler_{other.scheduler_},
root_task_{other.root_task_},
current_task_{other.current_task_},
task_stack_{other.task_stack_},
id_{other.id_} {}
thread_state& operator=(const thread_state& other) {
scheduler_ = other.scheduler_;
root_task_ = other.root_task_;
current_task_ = other.current_task_;
task_stack_ = other.task_stack_;
id_ = other.id_;
return *this;
}
}; };
} }
} }
......
...@@ -14,8 +14,9 @@ namespace pls { ...@@ -14,8 +14,9 @@ namespace pls {
} }
for (unsigned int i = 0; i < num_threads_; i++) { for (unsigned int i = 0; i < num_threads_; i++) {
new(memory_->thread_state_for(i)) thread_state{this, memory_->task_stack_for(i), i}; // Placement new is required, as the memory of `memory_` is not required to be initialized.
*memory_->thread_for(i) = base::start_thread(&worker_routine, memory_->thread_state_for(i)); new((void*)memory_->thread_state_for(i)) thread_state{this, memory_->task_stack_for(i), i};
new ((void*)memory_->thread_for(i))base::thread<void(*)(), thread_state>(&worker_routine, memory_->thread_state_for(i));
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment