#include "tile/base/internal/index_alloc.h"

#include "tile/base/thread/scoped_lock.h"

namespace tile {
namespace internal {
std::size_t
IndexAlloc::Next()
{
    ScopedLock _(lock_);
    if (!recycled_.empty()) {
        auto rc = recycled_.back();
        recycled_.pop_back();
        return rc;
    }
    return current_++;
}

void
IndexAlloc::Free(std::size_t index)
{
    ScopedLock _(lock_);
    recycled_.push_back(index);
}

}// namespace internal
}// namespace tile
