Alive thread implemented

This commit is contained in:
2026-04-11 09:50:59 +02:00
parent 8e5381fda2
commit 52aa0cac10
10 changed files with 215 additions and 31 deletions

33
shm.cpp
View File

@@ -211,6 +211,11 @@ public:
return new ShmSem(name, owner);
}
public:
void takeOwnership() {
_owner = true;
}
public:
ShmApiBase(const char *name, size_t size, bool owner) {
char *buf = reinterpret_cast<char *>(malloc(strlen(name) + 50));
@@ -520,11 +525,15 @@ public:
ReleaseSemaphore(_sem, 1, NULL);
}
void wait() {
DWORD r = WaitForSingleObject(_sem, INFINITE);
bool wait(int ms) {
DWORD r = WaitForSingleObject(_sem, ms);
if (r != WAIT_OBJECT_0) {
ERROR1("sem_wait error: %ld\n", r);
if (r != WAIT_TIMEOUT) {
ERROR1("sem_wait error: %ld\n", r);
}
return false;
}
return true;
}
bool trywait() {
@@ -535,6 +544,10 @@ public:
return r == WAIT_OBJECT_0;
}
void takeOwnership() {
_owner = true;
}
public:
ShmSemApi(const char *n, bool owner) {
_name = _strdup(n);
@@ -610,6 +623,11 @@ void *Shm::ref(int place)
return _shm_api->ref(place);
}
void Shm::takeOwnership()
{
_shm_api->takeOwnership();
}
void Shm::info(int &usage, int &free_depth, int &free_size, int &item_depth, int &item_size, double &usage_factor)
{
_shm_api->info(usage, free_depth, free_size, item_depth, item_size, usage_factor);
@@ -635,14 +653,19 @@ void ShmSem::post() {
_api->post();
}
void ShmSem::wait() {
_api->wait();
bool ShmSem::wait(int ms) {
return _api->wait(ms);
}
bool ShmSem::trywait() {
return _api->trywait();
}
void ShmSem::takeOwnership()
{
_api->takeOwnership();
}
ShmSem::ShmSem(const char *n, bool owner) {
_api = new ShmSemApi(n, owner);
}