shared: Begin basic ConcurrentQueue

This commit is contained in:
Albert S. 2022-04-14 14:57:16 +02:00
szülő 478d57b342
commit 56414ee5e2
5 fájl változott, egészen pontosan 76 új sor hozzáadva és 8 régi sor törölve

Fájl megtekintése

@ -35,20 +35,20 @@ void enableSandbox(QString socketPath)
EXILE_SYSCALL_VOW_PROT_EXEC | EXILE_SYSCALL_VOW_PROC | EXILE_SYSCALL_VOW_SHM |
EXILE_SYSCALL_VOW_FSNOTIFY | EXILE_SYSCALL_VOW_IOCTL;
if(exile_append_path_policy(policy, EXILE_FS_ALLOW_ALL_READ | EXILE_FS_ALLOW_REMOVE_FILE, "/") != 0)
if(exile_append_path_policies(policy, EXILE_FS_ALLOW_ALL_READ | EXILE_FS_ALLOW_REMOVE_FILE, "/") != 0)
{
qCritical() << "Failed to append a path to the path policy";
exit(EXIT_FAILURE);
}
if(exile_append_path_policy(policy, EXILE_FS_ALLOW_ALL_READ | EXILE_FS_ALLOW_ALL_WRITE, appDataLocation.c_str()) !=
0)
if(exile_append_path_policies(policy, EXILE_FS_ALLOW_ALL_READ | EXILE_FS_ALLOW_ALL_WRITE,
appDataLocation.c_str()) != 0)
{
qCritical() << "Failed to append a path to the path policy";
exit(EXIT_FAILURE);
}
if(exile_append_path_policy(policy, EXILE_FS_ALLOW_ALL_READ | EXILE_FS_ALLOW_ALL_WRITE,
cacheDataLocation.c_str()) != 0)
if(exile_append_path_policies(policy, EXILE_FS_ALLOW_ALL_READ | EXILE_FS_ALLOW_ALL_WRITE,
cacheDataLocation.c_str()) != 0)
{
qCritical() << "Failed to append a path to the path policy";
exit(EXIT_FAILURE);

Fájl megtekintése

@ -0,0 +1 @@
#include "concurrentqueue.h"

67
shared/concurrentqueue.h Normal file
Fájl megtekintése

@ -0,0 +1,67 @@
#ifndef CONCURRENTQUEUE_H
#define CONCURRENTQUEUE_H
#include <QList>
#include <QMutex>
#include <QSemaphore>
#define QUEUE_SIZE 10000
template <class T> class ConcurrentQueue : protected QList<T>
{
protected:
QMutex mutex;
QSemaphore avail{QUEUE_SIZE};
public:
void enqueue(const T &t)
{
avail.acquire(1);
QMutexLocker locker(&mutex);
QList<T>::append(t);
}
QVector<T> dequeue(int batchsize)
{
avail.release(batchsize);
// TODO: this sucks
QVector<T> result;
QMutexLocker locker(&mutex);
for(int i = 0; i < batchsize; i++)
{
result.append(QList<T>::takeFirst());
}
return result;
}
void enqueue(const QVector<T> &t)
{
QList<T> tmp(t.begin(), t.end());
avail.acquire(t.size());
QMutexLocker locker(&mutex);
QList<T>::append(tmp);
}
unsigned int remaining()
{
return QUEUE_SIZE - avail.available();
}
void clear()
{
QMutexLocker locker(&mutex);
QList<T>::clear();
avail.release(QUEUE_SIZE);
}
bool dequeue(T &result)
{
QMutexLocker locker(&mutex);
if(QList<T>::isEmpty())
return false;
avail.release(1);
result = QList<T>::takeFirst();
return true;
}
};
#endif // CONCURRENTQUEUE_H

Fájl megtekintése

@ -37,7 +37,7 @@ void SandboxedProcessor::enableSandbox(QString readablePath)
if(!readablePath.isEmpty())
{
std::string readablePathLocation = readablePath.toStdString();
if(exile_append_path_policy(policy, EXILE_FS_ALLOW_ALL_READ, readablePathLocation.c_str()) != 0)
if(exile_append_path_policies(policy, EXILE_FS_ALLOW_ALL_READ, readablePathLocation.c_str()) != 0)
{
qCritical() << "Failed to add path policies";
exit(EXIT_FAILURE);
@ -102,7 +102,7 @@ int SandboxedProcessor::process()
}
catch(LooqsGeneralException &e)
{
Logger::error() << "Error while processing" << absPath << ":" << e.message << Qt::endl;
Logger::error() << "SandboxedProcessor: Error while processing" << absPath << ":" << e.message << Qt::endl;
return 3 /* PROCESSFAIL */;
}

@ -1 +1 @@
Subproject commit 4824c6eaa9043878daaba7b3778338f5bf913f06
Subproject commit ea66ef76ebb88a43ac25c9a86f8fcab8efa130b2