Single bit locks

Getting one bit of data is not as hard as you may think. In our case, for example, most of the integer data type that's used to store a card number is unused. We only need 6 bits to represent numbers from 0 to 51, which means that the other 24 bits are unused. In most cases, you'll be able to find one such spare bit in existing data (if not, you can still implement lock striping by introducing additional locks).

To make the code clearer, I have extracted the logic that maintains the lock-striped array of cards into a separate record of type TLockStripingArray. It is defined in the LockStripingArray unit, as follows:

type  TLockStripingArray = record  private const    CMaskBit = 31;    CBitMask = 1 SHL CMaskBit;  var FData: TArray<integer>; ...

Get Hands-On Design Patterns with Delphi now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.