mirror of
https://github.com/mmueller41/genode.git
synced 2026-01-21 20:42:56 +01:00
Use native threads.
This commit is contained in:
@@ -1,46 +1,62 @@
|
||||
#include <base/component.h>
|
||||
#include <thread>
|
||||
#include <iostream>
|
||||
#include <sched.h>
|
||||
#include <unistd.h>
|
||||
|
||||
namespace ThreadTest {
|
||||
class Test;
|
||||
#include <timer_session/connection.h>
|
||||
#include <base/heap.h>
|
||||
#include <cstdint>
|
||||
namespace Thread_test {
|
||||
class Tester;
|
||||
class Test_thread;
|
||||
}
|
||||
|
||||
class ThreadTest::Test
|
||||
using namespace Genode;
|
||||
|
||||
class Thread_test::Test_thread : public Thread
|
||||
{
|
||||
private:
|
||||
Env &_env;
|
||||
uint16_t _id;
|
||||
Timer::Connection _timer{_env};
|
||||
|
||||
public:
|
||||
List_element<Test_thread> _list_element{this};
|
||||
|
||||
void execute()
|
||||
Test_thread(Env &env, uint16_t id, Location &location) : _env(env), _id(id) : Thread(env, Name("test_", location.xpos(), "x", location.ypos()), 4 * 4096, location, Weight(), env.cpu())
|
||||
{ }
|
||||
|
||||
void entry() override
|
||||
{
|
||||
while(true) {
|
||||
Genode::log("Pong from thread ", _id);
|
||||
_timer.msleep(_id * 1000);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class Thread_test::Tester
|
||||
{
|
||||
typedef List<List_element<Thread_test::Test_thread>> Thread_list;
|
||||
|
||||
private:
|
||||
Env &_env;
|
||||
Heap _heap{_env.ram(), _env.rm()};
|
||||
Thread_list _threads{};
|
||||
|
||||
public:
|
||||
Tester(Env &env) : _env(env)
|
||||
{
|
||||
while(true) {
|
||||
Genode::log("Hello world");
|
||||
//std::cout << "Hello world" << std::endl;
|
||||
//std::this_thread::sleep_for(std::chrono::seconds(5));
|
||||
sleep(2);
|
||||
Affinity::Space space = env.cpu().affinity_space();
|
||||
|
||||
for (unsigned i = 0; i < space.total(); i++) {
|
||||
Affinity::Location location = env.cpu().affinity_space().location_of_index(i);
|
||||
Test_thread *thread = new (_heap) Test_thread(env, i, location);
|
||||
thread->start();
|
||||
|
||||
_threads.insert(&thread->_list_element);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(void)
|
||||
void Component::construct(Genode::Env &env)
|
||||
{
|
||||
/* Create test posix thread via std::thread API */
|
||||
ThreadTest::Test test;
|
||||
auto test_thread = std::thread([&] { test.execute(); });
|
||||
|
||||
/* Print native threads affinity */
|
||||
|
||||
test_thread.join();
|
||||
return 0;
|
||||
static Thread_test::Tester tester(env);
|
||||
Genode::log("Thread tester constructed.");
|
||||
}
|
||||
|
||||
//void Component::construct(Genode::Env &env)
|
||||
//{
|
||||
//static ThreadTest::Test test;
|
||||
//Genode::log("ThreadTest constructed.");
|
||||
//test.execute();
|
||||
////std::thread([&]
|
||||
////{ main.execute(); });
|
||||
//}
|
||||
|
||||
Reference in New Issue
Block a user