private int ReserveSlot()
{
// This will be called with the context crst held so we
// don't take a lock here)
if (_ctxStatics == null)
{
// allocate the first bucket
_ctxStatics = new Object[STATICS_BUCKET_SIZE];
// set next bucket field to null
_ctxStatics[0] = null;
_ctxStaticsFreeIndex = 1;
_ctxStaticsCurrentBucket = 0;
}
// See if we have to allocate a new bucket
if (_ctxStaticsFreeIndex == STATICS_BUCKET_SIZE)
{
Object[] newBucket = new Object[STATICS_BUCKET_SIZE];
// walk the chain to locate the last bucket
Object[] bucket = _ctxStatics;
while (bucket[0] != null)
{
bucket = (Object[]) bucket[0];
}
// chain in the new bucket
bucket[0] = newBucket;
_ctxStaticsFreeIndex = 1;
_ctxStaticsCurrentBucket++;
}
// bucket# in highWord, index in lowWord
return _ctxStaticsFreeIndex++|_ctxStaticsCurrentBucket<<16;
}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~