This class tracks the bookkeeping of chip allocation while leaving the corresponding memory management to someone else. The implementation requires that chip allocation be single-threaded (presumably by some owner thread), but is thread-safe with respect to deallocation.
A given "chip" may be in one of three states:
Allocation is double-buffered in a sense: at the beginning of each allocation round, the owning thread unions the current set of zombie chips into the usable set; in-use chips are ignored.
The class has two members to support higher-level functionality:
_owner: an opaque pointer which is used to verify that blocks are being released properly It is set by the block_list but never inspected. It is used by derived classes.
_next: an embedded linked list node for use by the owner and otherwise ignored by the implementation
Definition at line 128 of file mem_block.h.
Public Types | |
| enum | |
Public Member Functions | |
| NORET | block_bits (size_t chip_count) |
| Construct bitmaps for chip_count chips. Used by block_of_chips. | |
| size_t | acquire_contiguous (size_t chip_count) |
| acquire chip_count contiguous chips by finding adjacent bits in _usable_chips | |
| void | release_contiguous (size_t idx, size_t chip_count) |
| release chip_count contiguous chips by setting the adjacent bits in _zombie_chips | |
| size_t | zombie_count () const |
| Return number of released-but-as-yet-unusable blocks. | |
| size_t | usable_count () const |
| Return number of usable blocks. | |
| void | recycle () |
| Make the zombied (released but not yet reusable) chips available. | |
| void | fake_full () |
| Make the block advertise that it has nothing to give. This is an optimization; used in block_list::block_list (q.v.). | |
1.4.7