libcruft-util/typeidx.cpp

28 lines
824 B
C++

/*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* Copyright 2017 Danny Robson <danny@nerdcruft.net>
*/
#include "typeidx.hpp"
#include <atomic>
///////////////////////////////////////////////////////////////////////////////
static std::atomic<int> counter;
//-----------------------------------------------------------------------------
int
cruft::detail::typeidx_next ()
{
// We can't return zero, but we want to optimise access to the static
// (which means we can't have it locally due to initialisation locking).
//
// Ensure we use pre-increment so that we can utilise zero static
// initialisation instead.
return ++counter;
}