Merge branch 'master' into cpp-11

# Conflicts:
#	src/stdafx.h
This commit is contained in:
Jonathan G Rennison
2018-04-26 23:59:13 +01:00
223 changed files with 3309 additions and 1985 deletions

View File

@@ -195,10 +195,10 @@ public:
inline void Push(const Titem &item)
{
if (this->value != Tinvalid) {
ThreadMutexLocker lock(_pool.GetMutex());
Tindex new_item = _pool.Create();
ThreadMutexLocker lock(SmallStack::GetPool().GetMutex());
Tindex new_item = SmallStack::GetPool().Create();
if (new_item != Tmax_size) {
PooledSmallStack &pushed = _pool.Get(new_item);
PooledSmallStack &pushed = SmallStack::GetPool().Get(new_item);
pushed.value = this->value;
pushed.next = this->next;
pushed.branch_count = 0;
@@ -218,16 +218,16 @@ public:
if (this->next == Tmax_size) {
this->value = Tinvalid;
} else {
ThreadMutexLocker lock(_pool.GetMutex());
PooledSmallStack &popped = _pool.Get(this->next);
ThreadMutexLocker lock(SmallStack::GetPool().GetMutex());
PooledSmallStack &popped = SmallStack::GetPool().Get(this->next);
this->value = popped.value;
if (popped.branch_count == 0) {
_pool.Destroy(this->next);
SmallStack::GetPool().Destroy(this->next);
} else {
--popped.branch_count;
/* We can't use Branch() here as we already have the mutex.*/
if (popped.next != Tmax_size) {
++(_pool.Get(popped.next).branch_count);
++(SmallStack::GetPool().Get(popped.next).branch_count);
}
}
/* Accessing popped here is no problem as the pool will only set
@@ -257,11 +257,11 @@ public:
{
if (item == Tinvalid || item == this->value) return true;
if (this->next != Tmax_size) {
ThreadMutexLocker lock(_pool.GetMutex());
ThreadMutexLocker lock(SmallStack::GetPool().GetMutex());
const SmallStack *in_list = this;
do {
in_list = static_cast<const SmallStack *>(
static_cast<const Item *>(&_pool.Get(in_list->next)));
static_cast<const Item *>(&SmallStack::GetPool().Get(in_list->next)));
if (in_list->value == item) return true;
} while (in_list->next != Tmax_size);
}
@@ -269,7 +269,11 @@ public:
}
protected:
static SmallStackPool _pool;
static SmallStackPool &GetPool()
{
static SmallStackPool pool;
return pool;
}
/**
* Create a branch in the pool if necessary.
@@ -277,8 +281,8 @@ protected:
inline void Branch()
{
if (this->next != Tmax_size) {
ThreadMutexLocker lock(_pool.GetMutex());
++(_pool.Get(this->next).branch_count);
ThreadMutexLocker lock(SmallStack::GetPool().GetMutex());
++(SmallStack::GetPool().Get(this->next).branch_count);
}
}
};

View File

@@ -158,6 +158,23 @@ public:
}
}
/**
* Insert a new item at a specific position into the vector, moving all following items.
* @param item Position at which the new item should be inserted
* @return pointer to the new item
*/
inline T *Insert(T *item)
{
assert(item >= this->Begin() && item <= this->End());
size_t to_move = this->End() - item;
size_t start = item - this->Begin();
this->Append();
if (to_move > 0) MemMoveT(this->Begin() + start + 1, this->Begin() + start, to_move);
return this->Begin() + start;
}
/**
* Search for the first occurrence of an item.
* The '!=' operator of T is used for comparison.
@@ -232,13 +249,24 @@ public:
* @param count Number of consecutive items to remove.
*/
void ErasePreservingOrder(uint pos, uint count = 1)
{
ErasePreservingOrder(this->data + pos, count);
}
/**
* Remove items from the vector while preserving the order of other items.
* @param item First item to remove.
* @param count Number of consecutive items to remove.
*/
inline void ErasePreservingOrder(T *item, uint count = 1)
{
if (count == 0) return;
assert(pos < this->items);
assert(pos + count <= this->items);
assert(item >= this->Begin());
assert(item + count <= this->End());
this->items -= count;
uint to_move = this->items - pos;
if (to_move > 0) MemMoveT(this->data + pos, this->data + pos + count, to_move);
ptrdiff_t to_move = this->End() - item;
if (to_move > 0) MemMoveT(item, item + count, to_move);
}
/**