[Mammoth] Add a user-space semaphore object.

This commit is contained in:
Drew Galbraith 2023-11-22 10:55:40 -08:00
parent da3901e104
commit 4c2492e985
3 changed files with 27 additions and 0 deletions

View File

@ -10,6 +10,7 @@ add_library(mammoth STATIC
src/process.cpp
src/port_client.cpp
src/port_server.cpp
src/semaphore.cpp
src/thread.cpp
)

View File

@ -0,0 +1,15 @@
#pragma once
#include <ztypes.h>
class Semaphore {
public:
Semaphore();
~Semaphore();
void Wait();
void Signal();
private:
z_cap_t semaphore_cap_;
};

View File

@ -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_)); }