nsbaci 1.0
Loading...
Searching...
No Matches
semaphore.h
Go to the documentation of this file.
1
5
6#ifndef NSBACI_RUNTIME_SEMAPHORE_H
7#define NSBACI_RUNTIME_SEMAPHORE_H
8
9#include <cstdint>
10#include <unordered_map>
11
12#include "compilerTypes.h"
13#include "thread.h"
14
16
23class Semaphore {
24 public:
25 explicit Semaphore(int32_t initialCount = 0) : count(initialCount) {}
26
30 bool wait(nsbaci::types::ThreadID currentThread);
31
34 nsbaci::types::ThreadID signal();
35
37 int32_t getCount() const { return count; }
38
40 bool hasWaiting() const { return !blocked.empty(); }
41
42 private:
43 std::queue<nsbaci::types::ThreadID> blocked;
44 int32_t count;
45};
46
47} // namespace nsbaci::services::runtime
48
49namespace nsbaci::types {
50
59 std::unordered_map<MemoryAddr, nsbaci::services::runtime::Semaphore>;
60
61} // namespace nsbaci::types
62
63#endif // NSBACI_RUNTIME_SEMAPHORE_H
bool hasWaiting() const
Check if any threads are blocked.
Definition semaphore.h:40
nsbaci::types::ThreadID signal()
V operation (signal/increment).
Definition semaphore.cpp:15
bool wait(nsbaci::types::ThreadID currentThread)
P operation (wait/decrement).
Definition semaphore.cpp:4
int32_t getCount() const
Get current count (for debugging).
Definition semaphore.h:37
Type definitions for compiler-related operations.
Runtime services namespace for nsbaci.
Type definitions namespace for nsbaci (runtime-specific).
std::unordered_map< MemoryAddr, nsbaci::services::runtime::Semaphore > SemaphoreTable
Maps memory addresses to semaphores.
Definition semaphore.h:58
Thread class declaration for nsbaci runtime service.