mirror of
https://github.com/mmueller41/genode.git
synced 2026-01-21 12:32:56 +01:00
Added POSIX playground for trying out POSIX and stdlib-related functions.
This commit is contained in:
46
repos/mml/run/posix_playground.run
Normal file
46
repos/mml/run/posix_playground.run
Normal file
@@ -0,0 +1,46 @@
|
||||
build "core init timer app/posix_playground"
|
||||
create_boot_directory
|
||||
|
||||
install_config {
|
||||
<config>
|
||||
<parent-provides>
|
||||
<service name="LOG"/>
|
||||
<service name="LOG"/>
|
||||
<service name="PD"/>
|
||||
<service name="CPU"/>
|
||||
<service name="ROM"/>
|
||||
<service name="RAM"/>
|
||||
<service name="IRQ"/>
|
||||
<service name="IO_MEM"/>
|
||||
<service name="IO_PORT"/>
|
||||
<service name="CAP"/>
|
||||
<service name="RM"/>
|
||||
<service name="SIGNAL"/>
|
||||
</parent-provides>
|
||||
<default-route>
|
||||
<any-service><parent/><any-child/></any-service>
|
||||
</default-route>
|
||||
<default caps="200"/>
|
||||
<start name="timer">
|
||||
<resource name="RAM" quantum="1M"/>
|
||||
<provides><service name="Timer"/></provides>
|
||||
<route>
|
||||
<any-service><parent/><any-child/></any-service>
|
||||
</route>
|
||||
</start>
|
||||
<start name="posix_playground">
|
||||
<resource name="RAM" quantum="10M"/>
|
||||
<route>
|
||||
<service name="Timer"><child name="timer"/></service>
|
||||
<any-service><parent/><any-child/></any-service>
|
||||
</route>
|
||||
</start>
|
||||
</config>
|
||||
}
|
||||
|
||||
set boot_modules {
|
||||
core init timer vfs.lb.so ld.lib.so libc.lib.so libm.lib.so stdcxx.lib.so posix_playground
|
||||
}
|
||||
|
||||
build_boot_image $boot_modules
|
||||
append qemu_args "-nographic -m 64"
|
||||
49
repos/mml/src/app/posix_playground/main.cc
Normal file
49
repos/mml/src/app/posix_playground/main.cc
Normal file
@@ -0,0 +1,49 @@
|
||||
#include <thread>
|
||||
#include <base/component.h>
|
||||
#include <chrono>
|
||||
#include <memory>
|
||||
#include <cstdint>
|
||||
#include <vector>
|
||||
|
||||
namespace Posix_playground {
|
||||
class Chrono_thread;
|
||||
}
|
||||
|
||||
class Posix_playground::Chrono_thread {
|
||||
|
||||
private:
|
||||
std::uint16_t _id;
|
||||
|
||||
public:
|
||||
Chrono_thread(std::uint16_t id) : _id(id) { }
|
||||
|
||||
void execute()
|
||||
{
|
||||
while (true) {
|
||||
Genode::log("Pong from Thread ", _id);
|
||||
auto start = std::chrono::steady_clock::now();
|
||||
std::this_thread::sleep_for(std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::milliseconds(_id * 1000)));
|
||||
auto end = std::chrono::steady_clock::now();
|
||||
Genode::log("Thread ", _id, " woke up after ", std::chrono::duration_cast<std::chrono::milliseconds>(end - start));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
int main(void) {
|
||||
Genode::log("Starting POSIX stdcxx playground");
|
||||
|
||||
Genode::log("Let's start some threads");
|
||||
|
||||
std::vector<Posix_playground::Chrono_thread&> thread_objs(4);
|
||||
std::vector<std::unique_ptr<std::thread>> thread_list(4);
|
||||
|
||||
for (int i = 0; i < 4; i++) {
|
||||
Posix_playground::Chrono_thread thread_objs[i] = *new Posix_playground::Chrono_thread(i);
|
||||
auto thread = std::make_unique<std::thread>([&]
|
||||
{ thread_objs[i].execute(); });
|
||||
thread_list.push_back(thread);
|
||||
thread->join();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
5
repos/mml/src/app/posix_playground/target.mk
Normal file
5
repos/mml/src/app/posix_playground/target.mk
Normal file
@@ -0,0 +1,5 @@
|
||||
TARGET = thread_test
|
||||
SRC_CC = thread_test.cc
|
||||
LIBS += base posix libm libc stdcxx
|
||||
CXXFLAGS += -Wno-error
|
||||
|
||||
Reference in New Issue
Block a user