0ad/source/lib/allocators/unique_range.cpp
janwas 2374caac3e major refactor of file/io and alignment code. requires update-workspaces
. completely rewrite waio - use IOCP, add several hardcore
optimizations. now outperforms the
  AS SSD and ATTO benchmarks when writing
. refactor file interface - use LIO_READ instead of 'r', allow access to
file descriptor.
. completely rewrite the IO wrapper. now much more simple, less CPU
overhead, adds
  support for pre-issue/post-completion hooks and preallocation.
  io::Run defaults to simple synchronous IO; use io::Parameters to get
asynchronous.
. add alignment.h with constants and Align() function template (more
efficient than
  round_up for compile-time constants)
. add UniqueRange - similar to C++0x unique_ptr (emulated for C++03),
plus a
  built-in size. avoids expensive thread-safe reference counting in
shared_ptr.

cleanup:
- move fat_time functions into archive_zip
- remove no longer needed io_align and block_cache
- reduce dependencies in sysdep/compiler (move parts to
code_annotation.h)
- move IOCP into separate file (reused by waio)

This was SVN commit r9350.
2011-04-29 19:10:34 +00:00

40 lines
1.1 KiB
C++

#include "precompiled.h"
#include "lib/allocators/unique_range.h"
#include "lib/sysdep/cpu.h" // cpu_AtomicAdd
#include "lib/sysdep/rtl.h" // rtl_FreeAligned
static void UniqueRangeDeleterNone(void* UNUSED(pointer), size_t UNUSED(size))
{
// (introducing this do-nothing function avoids having to check whether deleter != 0)
}
static void UniqueRangeDeleterAligned(void* pointer, size_t UNUSED(size))
{
return rtl_FreeAligned(pointer);
}
static UniqueRangeDeleter deleters[idxDeleterBits+1] = { UniqueRangeDeleterNone, UniqueRangeDeleterAligned };
static IdxDeleter numDeleters = 2;
IdxDeleter AddUniqueRangeDeleter(UniqueRangeDeleter deleter)
{
debug_assert(deleter);
IdxDeleter idxDeleter = cpu_AtomicAdd(&numDeleters, 1);
debug_assert(idxDeleter < (IdxDeleter)ARRAY_SIZE(deleters));
deleters[idxDeleter] = deleter;
return idxDeleter;
}
void CallUniqueRangeDeleter(void* pointer, size_t size, IdxDeleter idxDeleter) throw()
{
ASSERT(idxDeleter < numDeleters);
// (some deleters do not tolerate null pointers)
if(pointer)
deleters[idxDeleter](pointer, size);
}