RecallMemoryManager.hpp 2.63 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
27
28
/******************************************************************************
 *                      RecallMemoryManager.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

#include "castor/tape/tapeserver/threading/BlockingQueue.hpp"
#include "castor/tape/tapeserver/threading/Threading.hpp"
29
#include "castor/log/LogContext.hpp"
30
31

namespace castor {
32
33
34
35
namespace exception {
// Forward declaration  
class Exception;    
}
36
37
38
namespace tape {
namespace tapeserver {
namespace daemon {
39
40
// Forward declaration  
class MemBlock;
41
42
43
44
45
46
47
48
49
50
51
52
/**
 * The memory manager is responsible for allocating memory blocks and distributing
 * the free ones around to any class in need.
 */
class RecallMemoryManager {
public:
  
  /**
   * Constructor
   * @param numberOfBlocks: number of blocks to allocate
   * @param blockSize: size of each block
   */
53
  RecallMemoryManager(const size_t numberOfBlocks, const size_t blockSize,
54
          castor::log::LogContext& lc);
55
56
57
58
59
  
  /**
   * Are all sheep back to the farm?
   * @return 
   */
60
  bool areBlocksAllBack() throw();
61
62
63
64
65
  
  /**
   * Takes back a block which has been released by one of the clients
   * @param mb: the pointer to the block
   */
66
  void releaseBlock(MemBlock *mb);
67
  
68
69
70
71
72
  /**
   * Pop a free block from the free block queue of the memory manager
   * @return pointer to a free block
   */
  MemBlock* getFreeBlock();
73
74
75
76
  
  /**
   * Destructor
   */
77
  ~RecallMemoryManager();
78
79
80
81
82
83
84
85
86
87
88
  
private:
  /**
   * Total number of allocated memory blocks
   */
  size_t m_totalNumberOfBlocks;
  
  /**
   * Container for the free blocks
   */
  castor::tape::threading::BlockingQueue<MemBlock*> m_freeBlocks;
89
90
91
92
93
  
  /**
   * Logging. The class is not threaded, so it can be shared with its parent
   */
  castor::log::LogContext& m_lc;
94
95
96
97
};

}}}}