This commit is contained in:
2026-03-25 01:27:39 +01:00
parent eb4e15c66b
commit 8fe7e726a4
26 changed files with 1896 additions and 517 deletions

View File

@@ -1,4 +1,5 @@
#include "shmqueue.h"
#include <string.h>
ShmQueue::ShmQueue(Shm *shm, ShmSlot slot, bool owner)
{
@@ -43,15 +44,15 @@ int ShmQueue::depth()
return d;
}
void ShmQueue::enqueue(int cmd, const QString &json_data)
void ShmQueue::enqueue(int cmd, const std::string &json_data)
{
QByteArray b(json_data.toUtf8());
size_t jd_size = json_data.size();
int str_place = _shm->alloc(jd_size + 1);
int str_place = _shm->alloc(b.size() + 1);
char *s;
ref(_shm, str_place, &s);
memcpy(s, b.constData(), b.size());
s[b.size()] = '\0';
memcpy(s, json_data.data(), jd_size);
s[jd_size] = '\0';
int item_place = _shm->alloc(sizeof(ShmQueueItem));
ShmQueueItem *item;
@@ -60,6 +61,11 @@ void ShmQueue::enqueue(int cmd, const QString &json_data)
item->data_place = str_place;
item->prev = _queue->last;
item->next = SHM_NULL;
if (_queue->last != SHM_NULL) {
ShmQueueItem *last_i;
ref(_shm, _queue->last, &last_i);
last_i->next = item_place;
}
_shm->lock();
_queue->last = item_place;
@@ -71,7 +77,13 @@ void ShmQueue::enqueue(int cmd, const QString &json_data)
_queue_sem->post();
}
bool ShmQueue::dequeue(int &cmd, QString &json_data, bool wait)
void ShmQueue::enqueue(int cmd)
{
std::string s;
enqueue(cmd, s);
}
bool ShmQueue::dequeue(int &cmd, std::string &json_data, bool wait)
{
if (wait) {
_queue_sem->wait();
@@ -96,7 +108,7 @@ bool ShmQueue::dequeue(int &cmd, QString &json_data, bool wait)
ShmPlace data_place = item->data_place;
char *data;
ref(_shm, data_place, &data);
json_data = QString::fromUtf8(data, strlen(data));
json_data = data;
_shm->free(data_place);
cmd = item->cmd;