RecallMemoryManager.hpp 2.4 KB
Newer Older
1
2
/*
 * @project        The CERN Tape Archive (CTA)
3
 * @copyright      Copyright(C) 2003-2021 CERN
4
5
6
7
 * @license        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 3 of the License, or
 *                 (at your option) any later version.
8
 *
9
10
11
12
 *                 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.
13
 *
14
15
16
 *                 You should have received a copy of the GNU General Public License
 *                 along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
17
18
19

#pragma once

20
#include "common/threading/BlockingQueue.hpp"
21
#include "common/threading/Thread.hpp"
Victor Kotlyar's avatar
Victor Kotlyar committed
22
#include "common/log/LogContext.hpp"
23
24

namespace castor {
25
26
27
28
namespace exception {
// Forward declaration  
class Exception;    
}
29
30
31
namespace tape {
namespace tapeserver {
namespace daemon {
32
33
// Forward declaration  
class MemBlock;
34
35
36
37
38
39
40
41
42
43
44
45
/**
 * 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
   */
46
  RecallMemoryManager(const size_t numberOfBlocks, const size_t blockSize,
Victor Kotlyar's avatar
Victor Kotlyar committed
47
          cta::log::LogContext&  lc);
48
49
50
51
52
  
  /**
   * Are all sheep back to the farm?
   * @return 
   */
53
  bool areBlocksAllBack() throw();
54
55
56
57
58
  
  /**
   * Takes back a block which has been released by one of the clients
   * @param mb: the pointer to the block
   */
59
  void releaseBlock(MemBlock *mb);
60
  
61
62
63
64
65
  /**
   * Pop a free block from the free block queue of the memory manager
   * @return pointer to a free block
   */
  MemBlock* getFreeBlock();
66
67
68
69
  
  /**
   * Destructor
   */
70
  ~RecallMemoryManager();
71
72
73
74
75
76
77
78
79
80
  
private:
  /**
   * Total number of allocated memory blocks
   */
  size_t m_totalNumberOfBlocks;
  
  /**
   * Container for the free blocks
   */
81
  cta::threading::BlockingQueue<MemBlock*> m_freeBlocks;
82
83
84
85
  
  /**
   * Logging. The class is not threaded, so it can be shared with its parent
   */
Victor Kotlyar's avatar
Victor Kotlyar committed
86
  cta::log::LogContext&  m_lc;
87
88
89
90
};

}}}}