]>
git.ipfire.org Git - thirdparty/squid.git/blob - src/FileMap.h
2 * Copyright (C) 1996-2022 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 08 Swap File Bitmap */
14 #include "store/forward.h"
16 /** A bitmap used for managing UFS StoreEntry "file numbers".
18 * Nth bit represents whether file number N is used.
19 * The map automatically grows to hold up to 2^24 bits.
20 * New bit is "off" or zero by default, representing unused fileno.
21 * TODO: consider using std::bitset instead.
29 /** Set the num-th bit in the FileMap
31 * \warning FileMap's backing storage will be extended as needed to
32 * hold the representation, but if the bit is already set
33 * it will break the file number accounting, so the caller must
34 * ensure that setBit is only called if the bit is not already set,
35 * by using testBit on it before.
37 bool setBit(sfileno num
);
39 /// Test whether the num-th bit in the FileMap is set
40 bool testBit(sfileno num
) const;
42 /** Clear the num-th bit in the FileMap
44 * \warning that clearBit doesn't do any bounds checking, nor it
45 * checks that the bit is set before clearing. The caller will have
46 * to ensure that both are true using testBit before clearing.
48 void clearBit(sfileno num
);
50 /** locate an unused slot in the FileMap, possibly at or after position suggestion
52 * Obtain the location of an unused slot in the FileMap,
53 * growing it if needed.
54 * The suggestion is only an advice; there is no guarantee
55 * that it will be followed.
57 sfileno
allocate(sfileno suggestion
);
59 /// return the max number of slots in the FileMap
60 int capacity() const {return capacity_
;}
62 /// return the number of used slots in the FileMap
63 int numFilesInMap() const {return usedSlots_
;}
65 /// grow the FileMap (size is doubled each time, up to 2^24 bits)
67 FileMap(const FileMap
&); //no copying
68 FileMap
& operator=(const FileMap
&); //no assignments
70 /// max number of files which can be tracked in the current store
72 /// used slots in the map
73 unsigned int usedSlots_
;
74 /// number of "long ints" making up the filemap
76 unsigned long *bitmap
;
79 #endif /* FILEMAP_H_ */