33 #ifndef LSST_AP_CHUNK_MANAGER_IMPL_H
34 #define LSST_AP_CHUNK_MANAGER_IMPL_H
39 #include "boost/noncopyable.hpp"
40 #include "boost/static_assert.hpp"
53 namespace lsst {
namespace ap {
namespace detail {
71 template <
typename EntryT,
int NumEntries>
82 EntryT *
find(
int const id) {
83 return const_cast<EntryT *
>(
doFind(
id));
87 EntryT
const *
find(
int const id)
const {
91 EntryT *
insert(
int const id);
95 bool erase(
int const id);
104 return NumEntries -
_size;
123 EntryT
const *
end()
const {
133 EntryT
const *
doFind(
int const id)
const;
148 template <
typename MutexT,
typename DataT,
typename TraitsT = DataTraits<DataT> >
151 BlockAllocator(
unsigned char const *
const ref, std::size_t
const offset);
154 void allocate(std::size_t *
const blockOffsets,
int const n);
155 void free(std::size_t
const *
const blockOffsets,
int const n);
163 (
sizeof(DataT) +
sizeof(
ChunkEntryFlag)) << TraitsT::ENTRIES_PER_BLOCK_LOG2;
207 bool isValid(
int const visitId)
const;
208 void print(std::ostream & os)
const;
209 void print(
int const visitId, std::ostream & os)
const;
218 template <
typename MutexT,
typename DataT,
typename TraitsT = DataTraits<DataT> >
222 typedef ChunkRef<Allocator, DataT, TraitsT>
Chunk;
227 static int const NUM_CHUNKS = TraitsT::MAX_CHUNKS_PER_FOV * MAX_VISITS_IN_FLIGHT;
242 std::vector<Chunk> & toRead,
243 std::vector<Chunk> & toWaitFor,
245 std::vector<int>
const & chunkIds
249 std::vector<Chunk> & toRead,
250 std::vector<Chunk> & toWaitFor,
255 std::vector<Chunk> & chunks,
256 std::vector<int>
const & chunkIds
265 void print(std::ostream & os)
const;
266 void print(
int const chunkId, std::ostream & os)
const;
267 void printVisit(
int const visitId, std::ostream & os)
const;
309 return blocks() + Chunk::BLOCK_SIZE * TraitsT::NUM_BLOCKS;
319 std::vector<Chunk> & toRead,
320 std::vector<Chunk> & toWaitFor,
322 std::vector<int>
const & chunkIds
326 std::vector<Chunk> & toRead,
327 std::vector<Chunk> & toWaitFor,
333 std::vector<Chunk> & chunks,
334 std::vector<int>
const & chunkIds
337 bool endVisit(
int const visitId,
bool const rollback);
341 void printVisit(
int const visitId, std::ostream & os)
const;
342 void printChunk(
int const chunkId, std::ostream & os)
const;
356 #endif // LSST_AP_CHUNK_MANAGER_IMPL_H
A class for manipulating a fixed set of bits at the individual bit level.
A manager for a set of chunks of a single type.
BlockAllocator< MutexT, DataT, TraitsT > Allocator
Wraps the C library timespec struct.
void rollbackAllExcept(int const visitId)
void printVisit(int const visitId, std::ostream &os) const
Provides basic chunk parameters at compile time.
bool checkForOwnership(std::vector< Chunk > &toRead, std::vector< Chunk > &toWaitFor, int const visitId)
Helper class for managing chunks of a particular type.
Encapsulates a POSIX condition variable.
bool relinquishOwnership(int const visitId, bool const rollback, VisitTracker const &tracker)
unsigned char ChunkEntryFlag
void waitForOwnership(std::vector< Chunk > &toRead, std::vector< Chunk > &toWaitFor, int const visitId, TimeSpec const &deadline)
void createOrRegisterInterest(std::vector< Chunk > &toRead, std::vector< Chunk > &toWaitFor, int const visitId, std::vector< int > const &chunkIds)
int getNextInChain() const
void free(std::size_t const *const blockOffsets, int const n)
BOOST_STATIC_ASSERT(TraitsT::ENTRIES_PER_BLOCK_LOG2 >=9)
ChunkDescriptor< TraitsT::MAX_BLOCKS_PER_CHUNK > Descriptor
int size() const
Returns the number of chunks under management.
EntryT _entries[NumEntries]
void printChunk(int const chunkId, std::ostream &os) const
A thread-safe memory block allocator that uses a Bitset to track which blocks (out of a fixed size po...
Condition< MutexT > _ownerCondition
static std::size_t const BLOCK_SIZE
static int const NUM_CHUNKS
bool isValid(int const visitId) const
int space() const
Returns the number of additional chunks that could be handled by this manager.
bool endVisit(int const visitId, bool const rollback)
EntryT const * find(int const id) const
Returns a pointer to the entry with the given identifier, or null if there is no such entry...
std::pair< EntryT *, bool > findOrInsert(int const id)
Classes for holding spatial chunks of things in memory.
bool isVisitInFlight(int const visitId)
Convenience wrapper for the C library timespec struct and a simple profiling class.
EntryT const * doFind(int const id) const
EntryT * find(int const id)
Returns a pointer to the entry with the given identifier, or null if there is no such entry...
ChunkRef< Allocator, DataT, TraitsT > Chunk
void printChunks(std::ostream &os) const
void printVisit(int const visitId, std::ostream &os) const
HashedSet< Descriptor, NUM_CHUNKS > _chunks
Master header file for the association pipeline.
A generic descriptor containing state for different kinds of chunks.
void getChunks(std::vector< Chunk > &chunks, std::vector< int > const &chunkIds)
BlockAllocator(unsigned char const *const ref, std::size_t const offset)
Compile time constants related to data types to be stored in chunks.
Simple wrappers for POSIX mutual exclusion locks.
EntryT * insert(int const id)
void setNextInChain(int const id)
void printVisits(std::ostream &os) const
static std::size_t blocks()
Returns the offset of the first data block (relative to its manager).
BOOST_STATIC_ASSERT(NumEntries< INT_MAX)
void failVisit(int const visitId)
static std::size_t size()
SubManager(unsigned char const *const ref, std::size_t const offset)
int _hashTable[2 *NumEntries]
State for a single visit to a field of view.
void getChunks(std::vector< Chunk > &chunks, std::vector< int > const &chunkIds)
SubManager< MutexT, DataT, TraitsT > Manager
void print(std::ostream &os) const
A set of up to NumEntries elements of type EntryT, hashed by an integer identifier.
void startVisit(std::vector< Chunk > &toRead, std::vector< Chunk > &toWaitFor, int const visitId, std::vector< int > const &chunkIds)
void registerVisit(int const visitId)
std::size_t const _offset
EntryT const * end() const
Bitset< boost::uint64_t, TraitsT::NUM_BLOCKS > Allocator
EntryT const * begin() const
Simple wrapper class for POSIX condition variables.
void print(std::ostream &os) const