Re: [PATCH 04/13 v2] msvcp90: Add implementaion of _Concurrent_vector_Internal_reserve.
Hi Hua, On 07/31/18 17:16, Hua Meng wrote:
+/* ?_Internal_reserve(a)_Concurrent_vector_base_v4@details(a)Concurrency@@IAEXIII(a)Z */ +/* ?_Internal_reserve(a)_Concurrent_vector_base_v4@details(a)Concurrency@@IEAAX_K00(a)Z */ +DEFINE_THISCALL_WRAPPER(_Concurrent_vector_base_v4__Internal_reserve, 16) +void __thiscall _Concurrent_vector_base_v4__Internal_reserve( + _Concurrent_vector_base_v4 *this, MSVCP_size_t size, + MSVCP_size_t element_size, MSVCP_size_t max_size) +{ + MSVCP_size_t block_idx, capacity; + int i; + void **new_segment; + + TRACE("(%p %ld %ld %ld)\n", this, size, element_size, max_size); + + if(size > max_size) _vector_base_v4__Internal_throw_exception(this, 0); + capacity = _Concurrent_vector_base_v4__Internal_capacity(this); + if(size <= capacity) return; + block_idx = _vector_base_v4__Segment_index_of(size - 1); + if(!this->first_block) + InterlockedCompareExchangeSizeT(&this->first_block, block_idx + 1, 0); + i = _vector_base_v4__Segment_index_of(capacity); + if(this->storage == this->segment) { + for(; i <= block_idx && i < STORAGE_SIZE; i++) + concurrent_vector_alloc_segment(this, i, element_size); + if(block_idx >= STORAGE_SIZE) { + new_segment = malloc(SEGMENT_SIZE * sizeof(void*)); + if(new_segment == NULL) _vector_base_v4__Internal_throw_exception(this, 2); + memset(new_segment, 0, SEGMENT_SIZE * sizeof(void*)); Please change it to: memset(new_segment, 0, SEGMENT_SIZE * sizeof(*new_segment)); + memcpy(new_segment, this->storage, STORAGE_SIZE * element_size); Copied data size is wrong here. There should be: memcpy(new_segment, this->storage, STORAGE_SIZE * sizeof(*new_segment)); + if(InterlockedCompareExchangePointer((void*)&this->segment, new_segment, + this->storage) != this->storage) + free(new_segment); + } + } + for(; i <= block_idx; i++) + concurrent_vector_alloc_segment(this, i, element_size); +}
Thanks, Piotr
participants (1)
-
Piotr Caban