forked from mirrors/0ad
387722d41e
improvements from work: - no longer export classes; instead inline functions where it makes sense (e.g. the scope timers) or export the member functions directly - fix icc11 warnings - add some comments This was SVN commit r6531.
48 lines
782 B
C++
48 lines
782 B
C++
#ifndef INCLUDED_SHARED_PTR
|
|
#define INCLUDED_SHARED_PTR
|
|
|
|
#include "lib/sysdep/arch/x86_x64/x86_x64.h"
|
|
|
|
struct DummyDeleter
|
|
{
|
|
template<class T>
|
|
void operator()(T*)
|
|
{
|
|
}
|
|
};
|
|
|
|
template<class T>
|
|
shared_ptr<T> DummySharedPtr(T* ptr)
|
|
{
|
|
return shared_ptr<T>(ptr, DummyDeleter());
|
|
}
|
|
|
|
struct ArrayDeleter
|
|
{
|
|
template<class T>
|
|
void operator()(T* p)
|
|
{
|
|
delete[] p;
|
|
}
|
|
};
|
|
|
|
// (note: uses CheckedArrayDeleter)
|
|
LIB_API shared_ptr<u8> Allocate(size_t size);
|
|
|
|
struct AlignedDeleter
|
|
{
|
|
template<class T>
|
|
void operator()(T* t)
|
|
{
|
|
_mm_free(t);
|
|
}
|
|
};
|
|
|
|
template<class T>
|
|
shared_ptr<T> AllocateAligned(size_t size)
|
|
{
|
|
return shared_ptr<T>((T*)_mm_malloc(size, x86_x64_L1CacheLineSize()), AlignedDeleter());
|
|
}
|
|
|
|
#endif // #ifndef INCLUDED_SHARED_PTR
|