Commit ed1c83f6 by Marcus Winter

Merge branch 'embb436_tasks_group_creation_thread_safety' into development

parents eec3dd7d 7aa7fb0f
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include <list> #include <list>
#include <embb/base/core_set.h> #include <embb/base/core_set.h>
#include <embb/base/mutex.h>
#include <embb/mtapi/c/mtapi.h> #include <embb/mtapi/c/mtapi.h>
#include <embb/tasks/action.h> #include <embb/tasks/action.h>
#include <embb/tasks/task.h> #include <embb/tasks/task.h>
...@@ -233,6 +234,8 @@ class Node { ...@@ -233,6 +234,8 @@ class Node {
mtapi_action_hndl_t action_handle_; mtapi_action_hndl_t action_handle_;
std::list<Queue*> queues_; std::list<Queue*> queues_;
std::list<Group*> groups_; std::list<Group*> groups_;
embb::base::Spinlock queue_lock_;
embb::base::Spinlock group_lock_;
}; };
} // namespace tasks } // namespace tasks
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include <embb/base/memory_allocation.h> #include <embb/base/memory_allocation.h>
#include <embb/base/exceptions.h> #include <embb/base/exceptions.h>
#include <embb/base/thread.h>
#include <embb/tasks/tasks.h> #include <embb/tasks/tasks.h>
#if TASKS_CPP_AUTOMATIC_INITIALIZE #if TASKS_CPP_AUTOMATIC_INITIALIZE
#include <embb/base/mutex.h> #include <embb/base/mutex.h>
...@@ -237,7 +238,11 @@ void Node::Finalize() { ...@@ -237,7 +238,11 @@ void Node::Finalize() {
Group & Node::CreateGroup() { Group & Node::CreateGroup() {
Group * group = embb::base::Allocation::New<Group>(); Group * group = embb::base::Allocation::New<Group>();
while (!group_lock_.TryLock(1024)) {
embb::base::Thread::CurrentYield();
}
groups_.push_back(group); groups_.push_back(group);
group_lock_.Unlock();
return *group; return *group;
} }
...@@ -252,7 +257,11 @@ void Node::DestroyGroup(Group & group) { ...@@ -252,7 +257,11 @@ void Node::DestroyGroup(Group & group) {
Queue & Node::CreateQueue(mtapi_uint_t priority, bool ordered) { Queue & Node::CreateQueue(mtapi_uint_t priority, bool ordered) {
Queue * queue = embb::base::Allocation::New<Queue>(priority, ordered); Queue * queue = embb::base::Allocation::New<Queue>(priority, ordered);
while (!queue_lock_.TryLock(1024)) {
embb::base::Thread::CurrentYield();
}
queues_.push_back(queue); queues_.push_back(queue);
queue_lock_.Unlock();
return *queue; return *queue;
} }
......
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