[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
31
zion/syscall/synchronization.cpp
Normal file
31
zion/syscall/synchronization.cpp
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
#include "syscall/synchronization.h"
|
||||
|
||||
#include "object/mutex.h"
|
||||
#include "scheduler/scheduler.h"
|
||||
|
||||
glcr::ErrorCode MutexCreate(ZMutexCreateReq* req) {
|
||||
auto& curr_proc = gScheduler->CurrentProcess();
|
||||
*req->mutex_cap = curr_proc.AddNewCapability(Mutex::Create());
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
glcr::ErrorCode MutexLock(ZMutexLockReq* req) {
|
||||
auto& curr_proc = gScheduler->CurrentProcess();
|
||||
auto cap = curr_proc.GetCapability(req->mutex_cap);
|
||||
RET_ERR(ValidateCapability<Mutex>(cap, kZionPerm_Lock));
|
||||
|
||||
auto mutex = cap->obj<Mutex>();
|
||||
mutex->Lock();
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
glcr::ErrorCode MutexRelease(ZMutexReleaseReq* req) {
|
||||
auto& curr_proc = gScheduler->CurrentProcess();
|
||||
auto cap = curr_proc.GetCapability(req->mutex_cap);
|
||||
// TODO: We may not want a separate permission for releasing the mutex.
|
||||
RET_ERR(ValidateCapability<Mutex>(cap, kZionPerm_Release));
|
||||
|
||||
auto mutex = cap->obj<Mutex>();
|
||||
mutex->Release();
|
||||
return glcr::OK;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue