Пример #1
0
TLSBlock&
DynamicThreadVector::operator[](unsigned dso)
{
	unsigned generation = TLSBlockTemplates::Get().GetGeneration(-1);
	if (_Generation() < generation) {
		for (unsigned i = 0; i < _Size(); i++) {
			TLSBlock& block = (*fVector)[i + 1];
			unsigned dsoGeneration
				= TLSBlockTemplates::Get().GetGeneration(dso);
			if (_Generation() < dsoGeneration && dsoGeneration <= generation)
				block.Destroy();
		}

		fGeneration->SetCounter(generation);
	}

	if (_Size() <= dso) {
		status_t result = _ResizeVector(dso + 1);
		if (result != B_OK)
			return fNullBlock;
	}

	TLSBlock& block = (*fVector)[dso + 1];
	if (block.IsInvalid()) {
		status_t result = block.Initialize(dso);
		if (result != B_OK)
			return fNullBlock;
	};

	return block;
}