[Mammoth] Add a user-space semaphore object.
This commit is contained in:
parent
da3901e104
commit
4c2492e985
|
@ -10,6 +10,7 @@ add_library(mammoth STATIC
|
||||||
src/process.cpp
|
src/process.cpp
|
||||||
src/port_client.cpp
|
src/port_client.cpp
|
||||||
src/port_server.cpp
|
src/port_server.cpp
|
||||||
|
src/semaphore.cpp
|
||||||
src/thread.cpp
|
src/thread.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <ztypes.h>
|
||||||
|
|
||||||
|
class Semaphore {
|
||||||
|
public:
|
||||||
|
Semaphore();
|
||||||
|
~Semaphore();
|
||||||
|
|
||||||
|
void Wait();
|
||||||
|
void Signal();
|
||||||
|
|
||||||
|
private:
|
||||||
|
z_cap_t semaphore_cap_;
|
||||||
|
};
|
|
@ -0,0 +1,11 @@
|
||||||
|
#include "mammoth/semaphore.h"
|
||||||
|
|
||||||
|
#include <zcall.h>
|
||||||
|
|
||||||
|
#include "mammoth/debug.h"
|
||||||
|
|
||||||
|
Semaphore::Semaphore() { check(ZSemaphoreCreate(&semaphore_cap_)); }
|
||||||
|
Semaphore::~Semaphore() { check(ZCapRelease(semaphore_cap_)); }
|
||||||
|
|
||||||
|
void Semaphore::Wait() { check(ZSemaphoreWait(semaphore_cap_)); }
|
||||||
|
void Semaphore::Signal() { check(ZSemaphoreSignal(semaphore_cap_)); }
|
Loading…
Reference in New Issue