Commit ee95a6f9 authored by David COME's avatar David COME
Browse files

Added interface for DiskXThreadPool

and refactor a bit of code into the interface
parent b1840206
......@@ -27,9 +27,10 @@
#include "castor/tape/tapeserver/daemon/DiskReadTask.hpp"
#include "castor/tape/tapeserver/threading/BlockingQueue.hpp"
#include "castor/tape/tapeserver/threading/Threading.hpp"
#include "DiskThreadPoolInterface.hpp"
#include <vector>
class DiskReadThreadPool {
class DiskReadThreadPool : public castor::tape::tapeserver::daemon::DiskThreadPoolInterface<DiskReadTask> {
public:
DiskReadThreadPool(int nbThread) {
for(int i=0; i<nbThread; i++) {
......@@ -55,7 +56,7 @@ public:
(*i)->waitThreads();
}
}
void push(DiskReadTask *t) { m_tasks.push(t); }
virtual void push(DiskReadTask *t) { m_tasks.push(t); }
void finish() {
/* Insert one endOfSession per thread */
for (size_t i=0; i<m_threads.size(); i++) {
......@@ -64,9 +65,6 @@ public:
}
private:
class endOfSession: public DiskReadTask {
virtual bool endOfWork() { return true; }
};
class DiskReadWorkerThread: private castor::tape::threading::Thread {
public:
DiskReadWorkerThread(DiskReadThreadPool & manager): m_manager(manager) {}
......
/*
* File: DiskThreadPoolInterface.h
* Author: dcome
*
* Created on March 18, 2014, 3:53 PM
*/
#ifndef DISKTHREADPOOLINTERFACE_H
#define DISKTHREADPOOLINTERFACE_H
namespace castor {
namespace tape {
namespace tapeserver {
namespace daemon {
template <class Task> class DiskThreadPoolInterface
{
protected :
class endOfSession: public Task {
virtual bool endOfWork() { return true; }
};
castor::tape::threading::BlockingQueue<Task*> m_tasks;
public :
virtual ~DiskThreadPoolInterface(){}
virtual void push(Task *t) =0;
};
}}}}
#endif /* DISKTHREADPOOLINTERFACE_H */
......@@ -28,9 +28,10 @@
#include "castor/tape/tapeserver/threading/BlockingQueue.hpp"
#include "castor/tape/tapeserver/threading/Threading.hpp"
#include "castor/tape/tapeserver/daemon/TaskInjector.hpp"
#include "DiskThreadPoolInterface.hpp"
#include <vector>
class DiskWriteThreadPool {
class DiskWriteThreadPool : public castor::tape::tapeserver::daemon::DiskThreadPoolInterface<DiskWriteTask> {
public:
DiskWriteThreadPool(int nbThread, int maxFilesReq, int maxBlocksReq):
m_jobInjector(NULL), m_filesQueued(0), m_blocksQueued(0),
......@@ -59,7 +60,7 @@ public:
(*i)->waitThreads();
}
}
void push(DiskWriteTask *t) {
virtual void push(DiskWriteTask *t) {
{
castor::tape::threading::MutexLocker ml(&m_counterProtection);
m_filesQueued += t->files();
......@@ -112,9 +113,6 @@ private:
return ret;
}
class endOfSession: public DiskWriteTask {
virtual bool endOfWork() { return true; }
};
class DiskWriteWorkerThread: private castor::tape::threading::Thread {
public:
DiskWriteWorkerThread(DiskWriteThreadPool & manager): m_manager(manager) {}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment