DiskReadThreadPool.hpp 2.96 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/******************************************************************************
 *                      DiskReadThreadPool.hpp
 *
 * This file is part of the Castor project.
 * See http://castor.web.cern.ch/castor
 *
 * Copyright (C) 2003  CERN
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * 
 *
 * @author Castor Dev team, castor-dev@cern.ch
 *****************************************************************************/

#pragma once

David COME's avatar
David COME committed
27
#include "castor/tape/tapeserver/daemon/DiskReadTaskInterface.hpp"
28
29
#include "castor/tape/tapeserver/threading/BlockingQueue.hpp"
#include "castor/tape/tapeserver/threading/Threading.hpp"
David COME's avatar
David COME committed
30
#include "castor/tape/tapeserver/daemon/DiskThreadPoolInterface.hpp"
31
#include "castor/tape/tapeserver/threading/AtomicCounter.hpp"
32
#include "castor/tape/tapeserver/threading/Threading.hpp"
33
#include "castor/log/LogContext.hpp"
34
35
#include <vector>

David COME's avatar
David COME committed
36
37
38
39
namespace castor {
namespace tape {
namespace tapeserver {
namespace daemon {
40
  class MigrationTaskInjector;
David COME's avatar
David COME committed
41
class DiskReadThreadPool : public DiskThreadPoolInterface<DiskReadTaskInterface> {
42
public:
43
44
  DiskReadThreadPool(int nbThread, int m_maxFilesReq,int m_maxBytesReq, 
          castor::log::LogContext lc);
45
46
47
48
49
  ~DiskReadThreadPool();
  void startThreads();
  void waitThreads();
  virtual void push(DiskReadTaskInterface *t);
  void finish();
50
51
52
53
  void setTaskInjector(MigrationTaskInjector* injector){
      m_injector = injector;
  }
  DiskReadTaskInterface* popAndRequestMore();
54
private:
55
  class DiskReadWorkerThread: private castor::tape::threading::Thread {
56
  public:
57
58
59
60
61
    DiskReadWorkerThread(DiskReadThreadPool & manager):
    threadID(m_nbActiveThread++),_this(manager),lc(_this.m_lc) {
       log::LogContext::ScopedParam param(lc, log::Param("threadID", threadID));
       lc.log(LOG_INFO,"DiskWrite Thread created");
    }
62
63
    void startThreads() { start(); }
    void waitThreads() { wait(); }
64
  private:
65
66
    static tape::threading::AtomicCounter<int> m_nbActiveThread;
    const int threadID;
67
    DiskReadThreadPool & _this;
68
69
70
    castor::log::LogContext lc;
    
    virtual void run();
71
72
  };
  std::vector<DiskReadWorkerThread *> m_threads;
73
  castor::log::LogContext m_lc;
74
75
76
77
  MigrationTaskInjector* m_injector;
  int m_maxFilesReq;
  int m_maxBytesReq;
  tape::threading::Mutex m_loopBackMutex;
78
};
David COME's avatar
David COME committed
79
80

}}}}