DiskReadThreadPool.hpp 2.57 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
32
#include "castor/tape/tapeserver/threading/AtomicCounter.hpp"
#include "castor/log/LogContext.hpp"
33
34
#include <vector>

David COME's avatar
David COME committed
35
36
37
38
39
namespace castor {
namespace tape {
namespace tapeserver {
namespace daemon {
  
David COME's avatar
David COME committed
40
class DiskReadThreadPool : public DiskThreadPoolInterface<DiskReadTaskInterface> {
41
public:
42
43
44
45
46
47
  DiskReadThreadPool(int nbThread,castor::log::LogContext lc);
  ~DiskReadThreadPool();
  void startThreads();
  void waitThreads();
  virtual void push(DiskReadTaskInterface *t);
  void finish();
48
49

private:
50
  class DiskReadWorkerThread: private castor::tape::threading::Thread {
51
  public:
52
53
54
55
56
    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");
    }
57
58
    void startThreads() { start(); }
    void waitThreads() { wait(); }
59
  private:
60
61
    static tape::threading::AtomicCounter<int> m_nbActiveThread;
    const int threadID;
62
    DiskReadThreadPool & _this;
63
64
65
    castor::log::LogContext lc;
    
    virtual void run();
66
67
  };
  std::vector<DiskReadWorkerThread *> m_threads;
68
  castor::log::LogContext m_lc;
69
};
David COME's avatar
David COME committed
70
71

}}}}