Mutually-exclusive lock pools

#include <x/lockpool.H>

typedef x::mutexpool<> blocklock_t;

blocklock_t mutexpool(blocklock_t::create());

blocklock_t::lockentry usagelock(mutexpool->addLockSet(false,

blocklock_t::lockentry blocklock(mutexpool->addLockSet(true

x::mutexpool is a specialization of a lock pool that implements the semantics of a mutually-exclusive lock. The mutually-exclusive lock poool allows only one value to be locked at the same time, but the same value may be locked multiple times. Attempts to place another lock value into the lock pool get blocked, until all existing locks, of the same value, are released.

The above example, using bool for a block value is convenient implementation of a "blocking lock" for some unspecified resource. The contract is that using this resource requires obtaining a false lock value. This allows multiple concurrent usage. Concurrent existence of multiple false values is allowed.

Acquiring a true lock value, in this example, effectively blocks usage of the protected resource. The true lock value gets acquired only after all existing false values no longer exist, and future false lock values won't get acquired until the true lock values are gone. Multiple true lock values may exist, blocking access to the resource, and false lock values won't get acquired until the last true lock is gone.

In this example, the true and false lock values are symmetric. Each one blocks the other lock value. The first parameter to this template class can be something other than a bool, resulting in the same semantics: once the first lock value is acquired, only same lock values may be acquired additionally; all other lock values are blocked until all existing lock values are gone.