[Zion] Add a mutex object with appropriate syscalls.
This commit is contained in:
parent
4c2237fa72
commit
4c04f9d561
19 changed files with 160 additions and 60 deletions
|
|
@ -54,16 +54,16 @@ z_err_t UnboundedMessageQueue::PushBack(uint64_t num_bytes, const void* bytes,
|
|||
z_err_t UnboundedMessageQueue::PopFront(uint64_t* num_bytes, void* bytes,
|
||||
uint64_t* num_caps, z_cap_t* caps,
|
||||
z_cap_t* reply_cap) {
|
||||
mutex_.Lock();
|
||||
mutex_->Lock();
|
||||
while (pending_messages_.empty()) {
|
||||
auto thread = gScheduler->CurrentThread();
|
||||
thread->SetState(Thread::BLOCKED);
|
||||
blocked_threads_.PushBack(thread);
|
||||
mutex_.Unlock();
|
||||
mutex_->Release();
|
||||
gScheduler->Yield();
|
||||
mutex_.Lock();
|
||||
mutex_->Lock();
|
||||
}
|
||||
mutex_.Unlock();
|
||||
mutex_->Release();
|
||||
|
||||
MutexHolder lock(mutex_);
|
||||
auto next_msg = pending_messages_.PeekFront();
|
||||
|
|
@ -162,16 +162,16 @@ glcr::ErrorCode SingleMessageQueue::PushBack(uint64_t num_bytes,
|
|||
glcr::ErrorCode SingleMessageQueue::PopFront(uint64_t* num_bytes, void* bytes,
|
||||
uint64_t* num_caps, z_cap_t* caps,
|
||||
z_cap_t* reply_port) {
|
||||
mutex_.Lock();
|
||||
mutex_->Lock();
|
||||
while (!has_written_) {
|
||||
auto thread = gScheduler->CurrentThread();
|
||||
thread->SetState(Thread::BLOCKED);
|
||||
blocked_threads_.PushBack(thread);
|
||||
mutex_.Unlock();
|
||||
mutex_->Release();
|
||||
gScheduler->Yield();
|
||||
mutex_.Lock();
|
||||
mutex_->Lock();
|
||||
}
|
||||
mutex_.Unlock();
|
||||
mutex_->Release();
|
||||
|
||||
MutexHolder lock(mutex_);
|
||||
if (has_read_) {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
|
||||
#include "capability/capability.h"
|
||||
#include "include/ztypes.h"
|
||||
#include "lib/mutex.h"
|
||||
#include "object/mutex.h"
|
||||
|
||||
class MessageQueue {
|
||||
public:
|
||||
|
|
@ -23,7 +23,7 @@ class MessageQueue {
|
|||
virtual bool empty() = 0;
|
||||
|
||||
protected:
|
||||
Mutex mutex_{"message"};
|
||||
glcr::RefPtr<Mutex> mutex_ = Mutex::Create();
|
||||
// FIXME: This maybe shouldn't be shared between classes since the
|
||||
// SingleMessageQueue should only ever have one blocked thread.
|
||||
glcr::IntrusiveList<Thread> blocked_threads_;
|
||||
|
|
|
|||
|
|
@ -1,11 +0,0 @@
|
|||
#include "lib/mutex.h"
|
||||
|
||||
#include "debug/debug.h"
|
||||
#include "scheduler/scheduler.h"
|
||||
|
||||
void Mutex::Lock() {
|
||||
while (__atomic_fetch_or(&lock_, 0x1, __ATOMIC_SEQ_CST) == 0x1) {
|
||||
// dbgln("Lock sleep: %s", name_);
|
||||
gScheduler->Preempt();
|
||||
}
|
||||
}
|
||||
|
|
@ -1,30 +0,0 @@
|
|||
#pragma once
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
class Mutex {
|
||||
public:
|
||||
Mutex(const char* name) : name_(name) {}
|
||||
|
||||
// FIXME: Block thread on lock rather than "preempting"
|
||||
void Lock();
|
||||
void Unlock() { lock_ = false; }
|
||||
|
||||
private:
|
||||
const char* name_;
|
||||
|
||||
uint8_t lock_ = 0;
|
||||
};
|
||||
|
||||
class MutexHolder {
|
||||
public:
|
||||
MutexHolder(Mutex& mutex) : mutex_(mutex) { mutex_.Lock(); }
|
||||
|
||||
~MutexHolder() { mutex_.Unlock(); }
|
||||
|
||||
MutexHolder(MutexHolder&) = delete;
|
||||
MutexHolder(MutexHolder&&) = delete;
|
||||
|
||||
private:
|
||||
Mutex& mutex_;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue