[Zion] Add a semaphore primitive with related syscalls.
This commit is contained in:
parent
2df1f6c006
commit
da3901e104
9 changed files with 107 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#include "syscall/synchronization.h"
|
||||
|
||||
#include "object/mutex.h"
|
||||
#include "object/semaphore.h"
|
||||
#include "scheduler/scheduler.h"
|
||||
|
||||
glcr::ErrorCode MutexCreate(ZMutexCreateReq* req) {
|
||||
|
|
@ -22,10 +23,35 @@ glcr::ErrorCode MutexLock(ZMutexLockReq* req) {
|
|||
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;
|
||||
}
|
||||
|
||||
glcr::ErrorCode SemaphoreCreate(ZSemaphoreCreateReq* req) {
|
||||
auto& curr_proc = gScheduler->CurrentProcess();
|
||||
*req->semaphore_cap = curr_proc.AddNewCapability(Semaphore::Create());
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
glcr::ErrorCode SemaphoreWait(ZSemaphoreWaitReq* req) {
|
||||
auto& curr_proc = gScheduler->CurrentProcess();
|
||||
auto cap = curr_proc.GetCapability(req->semaphore_cap);
|
||||
RET_ERR(ValidateCapability<Semaphore>(cap, kZionPerm_Wait));
|
||||
|
||||
auto semaphore = cap->obj<Semaphore>();
|
||||
semaphore->Wait();
|
||||
return glcr::OK;
|
||||
}
|
||||
|
||||
glcr::ErrorCode SemaphoreSignal(ZSemaphoreSignalReq* req) {
|
||||
auto& curr_proc = gScheduler->CurrentProcess();
|
||||
auto cap = curr_proc.GetCapability(req->semaphore_cap);
|
||||
RET_ERR(ValidateCapability<Semaphore>(cap, kZionPerm_Signal));
|
||||
|
||||
auto semaphore = cap->obj<Semaphore>();
|
||||
semaphore->Signal();
|
||||
return glcr::OK;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,3 +7,7 @@
|
|||
glcr::ErrorCode MutexCreate(ZMutexCreateReq* req);
|
||||
glcr::ErrorCode MutexLock(ZMutexLockReq* req);
|
||||
glcr::ErrorCode MutexRelease(ZMutexReleaseReq* req);
|
||||
|
||||
glcr::ErrorCode SemaphoreCreate(ZSemaphoreCreateReq* req);
|
||||
glcr::ErrorCode SemaphoreWait(ZSemaphoreWaitReq* req);
|
||||
glcr::ErrorCode SemaphoreSignal(ZSemaphoreSignalReq* req);
|
||||
|
|
|
|||
|
|
@ -88,6 +88,9 @@ extern "C" z_err_t SyscallHandler(uint64_t call_id, void* req) {
|
|||
CASE(MutexCreate);
|
||||
CASE(MutexLock);
|
||||
CASE(MutexRelease);
|
||||
CASE(SemaphoreCreate);
|
||||
CASE(SemaphoreWait);
|
||||
CASE(SemaphoreSignal);
|
||||
// syscall/debug.h
|
||||
CASE(Debug);
|
||||
default:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue