2017-05-29 17:21:11 +10:00
|
|
|
/*
|
2018-08-04 15:14:06 +10:00
|
|
|
* 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/.
|
2017-05-29 17:21:11 +10:00
|
|
|
*
|
|
|
|
* Copyright 2017 Danny Robson <danny@nerdcruft.net>
|
|
|
|
*/
|
|
|
|
|
2017-11-22 16:49:37 +11:00
|
|
|
#include "typeidx.hpp"
|
2017-05-29 17:21:11 +10:00
|
|
|
|
2018-04-05 12:14:11 +10:00
|
|
|
#include <atomic>
|
2017-05-29 17:21:11 +10:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2019-05-30 10:43:05 +10:00
|
|
|
static std::atomic<int> counter;
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2018-04-05 12:14:11 +10:00
|
|
|
int
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::detail::typeidx_next ()
|
2017-05-29 17:21:11 +10:00
|
|
|
{
|
2019-05-30 10:43:05 +10:00
|
|
|
// 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;
|
2017-05-29 17:21:11 +10:00
|
|
|
}
|