Files
filament/libs/utils/src/EntityManager.cpp
Mathias Agopian bc3aee118a code size and performance optimizations (#472)
* Clean-up EntityManager a bit

- use tsl::robin_set instead of std::set (which should have been unordered::set
  anyways).

- getListeners() now returns a vector which avoids to traverse a set twice.
  Turns out that copying the set wasn't as efficient as I thought.

* Improve jobsystem a bit

We recently added a job reference counting mechanism, but we were a bit
too aggressive about taking/release references.

Also make the API more complete by adding explicit retain/release,
which is needed to allow several threads to wait on the same job.

Also improve futex code by inlining it.
2018-11-12 14:11:31 -08:00

55 lines
1.8 KiB
C++

/*
* Copyright (C) 2017 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "EntityManagerImpl.h"
namespace utils {
EntityManager::EntityManager()
: mGens(new uint8_t[RAW_INDEX_COUNT]) {
// initialize all the generations to 0
std::fill_n(mGens, RAW_INDEX_COUNT, 0);
}
EntityManager::~EntityManager() {
delete [] mGens;
}
EntityManager& EntityManager::get() noexcept {
// note: we leak the EntityManager because it's more important that it survives everything else
// the leak is really not a problem because the process is terminating anyways.
static EntityManagerImpl* instance = new EntityManagerImpl;
return *instance;
}
void EntityManager::create(size_t n, Entity* entities) {
static_cast<EntityManagerImpl *>(this)->create(n, entities);
}
void EntityManager::destroy(size_t n, Entity* entities) noexcept {
static_cast<EntityManagerImpl *>(this)->destroy(n, entities);
}
void EntityManager::registerListener(EntityManager::Listener* l) noexcept {
static_cast<EntityManagerImpl *>(this)->registerListener(l);
}
void EntityManager::unregisterListener(EntityManager::Listener* l) noexcept {
static_cast<EntityManagerImpl *>(this)->unregisterListener(l);
}
} // namespace utils