- heap-alloc.cpp: allocate memory from env's heap.
- create-thread-deprecated.cpp: create deprecated thread.
- transfer-mem.cpp: transfer memory between two entrypoint.
Last active
September 29, 2016 15:01
-
-
Save sighingnow/f51a41bc2f5998f184cd085498d87dba to your computer and use it in GitHub Desktop.
Code snippets for Genode development.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Worker : Genode::Thread_deprecated<4096> { // the type argument is stack size, in bytes. | |
private: | |
void entry() { | |
Genode::log("entry of worker"); | |
while (1) { | |
} | |
} | |
public: | |
Handler() : Thread_deprecated("worker") { start(); } | |
~Handler() { Genode::log("destroy of worker"); } | |
}; | |
void Component::construct(Genode::Env &env) { | |
Timer::Connection main_timer; | |
Handler *handler = new (Genode::env()->heap()) Handler(); | |
main_timer.msleep(200); // set time duration to let the new thread run. | |
// other work. | |
destroy(Genode::env()->heap(), handler); // destory thread. | |
Genode::log("test create-thread-deprecated completed"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* config: | |
<start name="test-mingle-limit-mem"> | |
<resource name="RAM" quantum="10M"/> | |
</start> | |
*/ | |
void Component::construct(Genode::Env &env) { | |
int bound = 1 << 22; | |
Genode::log("before alloc consumed: ", Genode::env()->heap()->consumed()); | |
void *p = Genode::env()->heap()->alloc(bound); | |
Genode::memset(p, 0x00, bound); | |
Genode::printf("%p", p); | |
Genode::log("after alloc consumed: ", Genode::env()->heap()->consumed()); | |
destroy(Genode::env()->heap(), handler); | |
Genode::log("test alloc-mem completed"); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* transfer memory capability. | |
*/ | |
void Component::construct(Genode::Env &env) { | |
Genode::Ram_connection child_ram; | |
child_ram.ref_account(env.ram_session_cap()); // add reference count to the source memory cap. | |
Genode::log("child_ram available: ", child_ram.avail()); | |
env.ram().transfer_quota(child_ram.cap(), 1 << 20); // transfer the memory from source to target. | |
Genode::log("child_ram available after transfer: ", child_ram.avail()); | |
Genode::log("test transfer-mem completed"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment