[zion] Move IPC objects to share code
This commit is contained in:
parent
58df2c0ed2
commit
9dd457391c
14 changed files with 125 additions and 196 deletions
35
zion/object/ipc_object.cpp
Normal file
35
zion/object/ipc_object.cpp
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
#include "object/ipc_object.h"
|
||||
|
||||
#include "scheduler/scheduler.h"
|
||||
|
||||
glcr::ErrorCode IpcObject::Send(uint64_t num_bytes, const void* bytes,
|
||||
uint64_t num_caps, const z_cap_t* caps) {
|
||||
auto& message_queue = GetSendMessageQueue();
|
||||
MutexHolder lock(mutex_);
|
||||
RET_ERR(message_queue.PushBack(num_bytes, bytes, num_caps, caps));
|
||||
|
||||
if (blocked_threads_.size() > 0) {
|
||||
auto thread = blocked_threads_.PopFront();
|
||||
thread->SetState(Thread::RUNNABLE);
|
||||
gScheduler->Enqueue(thread);
|
||||
}
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
glcr::ErrorCode IpcObject::Recv(uint64_t* num_bytes, void* bytes,
|
||||
uint64_t* num_caps, z_cap_t* caps) {
|
||||
auto& message_queue = GetRecvMessageQueue();
|
||||
mutex_.Lock();
|
||||
while (message_queue.empty()) {
|
||||
auto thread = gScheduler->CurrentThread();
|
||||
thread->SetState(Thread::BLOCKED);
|
||||
blocked_threads_.PushBack(thread);
|
||||
mutex_.Unlock();
|
||||
gScheduler->Yield();
|
||||
mutex_.Lock();
|
||||
}
|
||||
mutex_.Unlock();
|
||||
|
||||
MutexHolder lock(mutex_);
|
||||
return message_queue.PopFront(num_bytes, bytes, num_caps, caps);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue