Endpoint syscalls implemented
This commit is contained in:
parent
69501bfe01
commit
c064af5fa7
27 changed files with 391 additions and 42 deletions
43
zion/object/endpoint.cpp
Normal file
43
zion/object/endpoint.cpp
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#include "object/endpoint.h"
|
||||
|
||||
#include "scheduler/scheduler.h"
|
||||
|
||||
glcr::RefPtr<Endpoint> Endpoint::Create() {
|
||||
return glcr::AdoptPtr(new Endpoint);
|
||||
}
|
||||
|
||||
glcr::ErrorCode Endpoint::Write(uint64_t num_bytes, const void* data,
|
||||
z_cap_t reply_port_cap) {
|
||||
MutexHolder h(mutex_);
|
||||
RET_ERR(message_queue_.PushBack(num_bytes, data, 1, &reply_port_cap));
|
||||
|
||||
if (blocked_threads_.size() > 0) {
|
||||
auto thread = blocked_threads_.PopFront();
|
||||
thread->SetState(Thread::RUNNABLE);
|
||||
gScheduler->Enqueue(thread);
|
||||
}
|
||||
|
||||
return glcr::OK;
|
||||
}
|
||||
glcr::ErrorCode Endpoint::Read(uint64_t* num_bytes, void* data,
|
||||
z_cap_t* reply_port_cap) {
|
||||
mutex_.Lock();
|
||||
while (message_queue_.empty()) {
|
||||
auto thread = gScheduler->CurrentThread();
|
||||
thread->SetState(Thread::BLOCKED);
|
||||
mutex_.Unlock();
|
||||
gScheduler->Yield();
|
||||
mutex_.Lock();
|
||||
}
|
||||
mutex_.Unlock();
|
||||
|
||||
MutexHolder h(mutex_);
|
||||
|
||||
uint64_t num_caps = 1;
|
||||
RET_ERR(message_queue_.PopFront(num_bytes, data, &num_caps, reply_port_cap));
|
||||
|
||||
if (num_caps != 1) {
|
||||
return glcr::INTERNAL;
|
||||
}
|
||||
return glcr::OK;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue