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 the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.