shared: Begin basic ConcurrentQueue
这个提交包含在:
父节点
478d57b342
当前提交
56414ee5e2
@ -35,19 +35,19 @@ void enableSandbox(QString socketPath)
|
|||||||
EXILE_SYSCALL_VOW_PROT_EXEC | EXILE_SYSCALL_VOW_PROC | EXILE_SYSCALL_VOW_SHM |
|
EXILE_SYSCALL_VOW_PROT_EXEC | EXILE_SYSCALL_VOW_PROC | EXILE_SYSCALL_VOW_SHM |
|
||||||
EXILE_SYSCALL_VOW_FSNOTIFY | EXILE_SYSCALL_VOW_IOCTL;
|
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";
|
qCritical() << "Failed to append a path to the path policy";
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(exile_append_path_policy(policy, EXILE_FS_ALLOW_ALL_READ | EXILE_FS_ALLOW_ALL_WRITE, appDataLocation.c_str()) !=
|
if(exile_append_path_policies(policy, EXILE_FS_ALLOW_ALL_READ | EXILE_FS_ALLOW_ALL_WRITE,
|
||||||
0)
|
appDataLocation.c_str()) != 0)
|
||||||
{
|
{
|
||||||
qCritical() << "Failed to append a path to the path policy";
|
qCritical() << "Failed to append a path to the path policy";
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
if(exile_append_path_policy(policy, EXILE_FS_ALLOW_ALL_READ | EXILE_FS_ALLOW_ALL_WRITE,
|
if(exile_append_path_policies(policy, EXILE_FS_ALLOW_ALL_READ | EXILE_FS_ALLOW_ALL_WRITE,
|
||||||
cacheDataLocation.c_str()) != 0)
|
cacheDataLocation.c_str()) != 0)
|
||||||
{
|
{
|
||||||
qCritical() << "Failed to append a path to the path policy";
|
qCritical() << "Failed to append a path to the path policy";
|
||||||
|
1
shared/concurrentqueue.cpp
普通文件
1
shared/concurrentqueue.cpp
普通文件
@ -0,0 +1 @@
|
|||||||
|
#include "concurrentqueue.h"
|
67
shared/concurrentqueue.h
普通文件
67
shared/concurrentqueue.h
普通文件
@ -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())
|
if(!readablePath.isEmpty())
|
||||||
{
|
{
|
||||||
std::string readablePathLocation = readablePath.toStdString();
|
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";
|
qCritical() << "Failed to add path policies";
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
@ -102,7 +102,7 @@ int SandboxedProcessor::process()
|
|||||||
}
|
}
|
||||||
catch(LooqsGeneralException &e)
|
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 */;
|
return 3 /* PROCESSFAIL */;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 4824c6eaa9043878daaba7b3778338f5bf913f06
|
Subproject commit ea66ef76ebb88a43ac25c9a86f8fcab8efa130b2
|
正在加载...
x
在新工单中引用
屏蔽一个用户