Skip to content
Snippets Groups Projects
Commit ff1fb4da authored by Avi Kivity's avatar Avi Kivity
Browse files

sched: default thread attributes

This makes it easier to create a thread with no special properties.
parent 1c6641c2
No related branches found
No related tags found
No related merge requests found
......@@ -86,12 +86,12 @@ void thread::yield()
}
thread::stack_info::stack_info()
: begin(), size()
: begin(malloc(65536)), size(65536), owned(true)
{
}
thread::stack_info::stack_info(void* _begin, size_t _size)
: begin(_begin), size(_size)
: begin(_begin), size(_size), owned(false)
{
auto end = align_down(begin + size, 16);
size = static_cast<char*>(end) - static_cast<char*>(begin);
......
......@@ -98,10 +98,7 @@ struct driver virtio_blk_driver = {
sizeof(_config.capacity));
debug(fmt("capacity of the device is %x") % (u64)_config.capacity);
void* stk1 = malloc(10000);
thread::attr attr;
attr.stack = {stk1, 10000};
thread* worker = new thread([this] { this->response_worker(); } , attr);
thread* worker = new thread([this] { this->response_worker(); });
worker->wake(); // just to keep gcc happy about unused var
_dev->add_dev_status(VIRTIO_CONFIG_S_DRIVER_OK);
......
......@@ -44,11 +44,8 @@ namespace virtio {
_avail_count = num;
msix_isr_list* isrs = new msix_isr_list;
void* stk1 = malloc(10000);
_callback = nullptr;
thread::attr attr;
attr.stack = {stk1, 10000};
thread* isr = new thread([this] { if (_callback) _callback(); }, attr);
thread* isr = new thread([this] { if (_callback) _callback(); });
isrs->insert(std::make_pair(_q_index, isr));
interrupt_manager::instance()->easy_register(_dev, *isrs);
......
......@@ -52,15 +52,19 @@ private:
class thread {
public:
class attr;
struct stack_info {
stack_info();
stack_info(void* begin, size_t size);
void* begin;
size_t size;
bool owned; // by thread
};
struct attr {
stack_info stack;
};
public:
explicit thread(std::function<void ()> func, attr attributes,
explicit thread(std::function<void ()> func, attr attributes = attr(),
bool main = false);
~thread();
template <class Pred>
......@@ -109,10 +113,6 @@ public:
bi::list_member_hook<> _thread_list_link;
};
struct thread::attr {
stack_info stack;
};
class timer_list {
public:
void fired();
......
......@@ -121,11 +121,8 @@ void test_threads()
test_threads_data tt;
tt.main = thread::current();
tt.t1ok = tt.t2ok = true;
thread::attr attr1, attr2;
attr1.stack = { new char[10000], 10000 };
attr2.stack = { new char[10000], 10000 };
tt.t1 = new thread([&] { test_thread_1(tt); }, attr1);
tt.t2 = new thread([&] { test_thread_2(tt); }, attr2);
tt.t1 = new thread([&] { test_thread_1(tt); });
tt.t2 = new thread([&] { test_thread_2(tt); });
thread::wait_until([&] { return test_ctr >= 1000; });
tt.t1->join();
tt.t2->join();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment