[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
33
zion/object/semaphore.h
Normal file
33
zion/object/semaphore.h
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
#pragma once
|
||||
|
||||
#include <glacier/container/intrusive_list.h>
|
||||
#include <glacier/memory/ref_ptr.h>
|
||||
|
||||
#include "include/ztypes.h"
|
||||
#include "object/kernel_object.h"
|
||||
#include "object/thread.h"
|
||||
|
||||
class Semaphore;
|
||||
|
||||
template <>
|
||||
struct KernelObjectTag<Semaphore> {
|
||||
static const uint64_t type = KernelObject::SEMAPHORE;
|
||||
};
|
||||
|
||||
class Semaphore : public KernelObject {
|
||||
public:
|
||||
uint64_t TypeTag() override { return KernelObject::SEMAPHORE; }
|
||||
static uint64_t DefaultPermissions() {
|
||||
return kZionPerm_Wait | kZionPerm_Signal;
|
||||
}
|
||||
|
||||
static glcr::RefPtr<Semaphore> Create();
|
||||
|
||||
void Wait();
|
||||
void Signal();
|
||||
|
||||
private:
|
||||
uint8_t lock_ = 0;
|
||||
|
||||
glcr::IntrusiveList<Thread> blocked_threads_;
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue