shared: Begin basic ConcurrentQueue
This commit is contained in:
orang tua
478d57b342
melakukan
56414ee5e2
10
gui/main.cpp
10
gui/main.cpp
@ -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);
|
||||
|
1
shared/concurrentqueue.cpp
Normal file
1
shared/concurrentqueue.cpp
Normal file
@ -0,0 +1 @@
|
||||
#include "concurrentqueue.h"
|
67
shared/concurrentqueue.h
Normal file
67
shared/concurrentqueue.h
Normal file
@ -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
|
@ -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
|
Memuat…
Reference in New Issue
Block a user