- applied review comments
- memory tracker x64 fix
This commit is contained in:
parent
1268343f98
commit
5223da467e
19 changed files with 2621 additions and 2650 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -9,3 +9,4 @@ evona_test/
|
|||
*.orig
|
||||
debug/
|
||||
release/
|
||||
/qteditor/QtEditor/Makefile
|
||||
|
|
|
@ -191,7 +191,8 @@
|
|||
<ClInclude Include="..\..\..\src\core\MT\semaphore.h" />
|
||||
<ClInclude Include="..\..\..\src\core\MT\spin_mutex.h" />
|
||||
<ClInclude Include="..\..\..\src\core\MT\task.h" />
|
||||
<ClInclude Include="..\..\..\src\core\MT\transaction_queue.h" />
|
||||
<ClInclude Include="..\..\..\src\core\MT\transaction.h" />
|
||||
<ClInclude Include="..\..\..\src\core\MT\lock_free_fixed_queue.h" />
|
||||
<ClInclude Include="..\..\..\src\core\Net\tcp_acceptor.h" />
|
||||
<ClInclude Include="..\..\..\src\core\Net\tcp_connector.h" />
|
||||
<ClInclude Include="..\..\..\src\core\Net\tcp_stream.h" />
|
||||
|
|
|
@ -84,9 +84,6 @@
|
|||
<ClInclude Include="..\..\..\src\core\MT\task.h">
|
||||
<Filter>MT</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\src\core\MT\transaction_queue.h">
|
||||
<Filter>MT</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\src\core\MTJD\base_entry.h">
|
||||
<Filter>MTJD</Filter>
|
||||
</ClInclude>
|
||||
|
@ -120,6 +117,12 @@
|
|||
<ClInclude Include="..\..\..\src\core\Net\tcp_stream.h">
|
||||
<Filter>Net</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\src\core\MT\transaction.h">
|
||||
<Filter>MT</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\src\core\MT\lock_free_fixed_queue.h">
|
||||
<Filter>MT</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="..\..\..\src\core\blob.cpp" />
|
||||
|
|
|
@ -5,8 +5,9 @@
|
|||
#include "core/array.h"
|
||||
#include "core/stack_allocator.h"
|
||||
#include "core/string.h"
|
||||
#include "core/MT/lock_free_fixed_queue.h"
|
||||
#include "core/MT/task.h"
|
||||
#include "core/MT/transaction_queue.h"
|
||||
#include "core/MT/transaction.h"
|
||||
#include "core/queue.h"
|
||||
|
||||
namespace Lux
|
||||
|
@ -35,7 +36,7 @@ namespace Lux
|
|||
static const int32_t C_MAX_TRANS = 16;
|
||||
|
||||
typedef MT::Transaction<AsyncItem> AsynTrans;
|
||||
typedef MT::TransactionQueue<AsynTrans, C_MAX_TRANS> TransQueue;
|
||||
typedef MT::LockFreeFixedQueue<AsynTrans, C_MAX_TRANS> TransQueue;
|
||||
typedef Queue<AsynTrans*, C_MAX_TRANS> InProgressQueue;
|
||||
typedef Array<AsyncItem> ItemsTable;
|
||||
typedef Array<IFileDevice*> DevicesTable;
|
||||
|
|
|
@ -171,7 +171,7 @@ namespace Lux
|
|||
}
|
||||
|
||||
|
||||
void stop() {} // TODO: implement stop
|
||||
void stop() {}
|
||||
|
||||
|
||||
void setBasePath(const char* base_path)
|
||||
|
|
|
@ -1,32 +1,17 @@
|
|||
#pragma once
|
||||
|
||||
#include "core/MT/atomic.h"
|
||||
#include "core/MT/event.h"
|
||||
#include "core/MT/semaphore.h"
|
||||
|
||||
namespace Lux
|
||||
{
|
||||
namespace MT
|
||||
{
|
||||
template <class T> struct Transaction
|
||||
template <class T, int32_t size> class LockFreeFixedQueue
|
||||
{
|
||||
static_assert(std::is_trivially_copyable<T>::value, "T must be trivially copyable");
|
||||
void setCompleted() { m_event.trigger(); }
|
||||
bool isCompleted() { return m_event.poll(); }
|
||||
void waitForCompletion() { return m_event.wait(); }
|
||||
void reset() { m_event.reset(); }
|
||||
|
||||
Transaction() : m_event(MT::EventFlags::MANUAL_RESET) { }
|
||||
|
||||
MT::Event m_event;
|
||||
T data;
|
||||
};
|
||||
|
||||
template <class T, int32_t size> class TransactionQueue
|
||||
{
|
||||
static_assert(std::is_trivially_copyable<T>::value, "T must be trivially copyable");
|
||||
static_assert(std::is_trivially_copyable<T>::value, "T must be trivially copyable!");
|
||||
public:
|
||||
TransactionQueue()
|
||||
LockFreeFixedQueue()
|
||||
: m_al(0)
|
||||
, m_fr(0)
|
||||
, m_rd(0)
|
||||
|
@ -43,7 +28,7 @@ namespace Lux
|
|||
}
|
||||
}
|
||||
|
||||
~TransactionQueue()
|
||||
~LockFreeFixedQueue()
|
||||
{
|
||||
}
|
||||
|
||||
|
@ -51,7 +36,7 @@ namespace Lux
|
|||
{
|
||||
do
|
||||
{
|
||||
while ((m_al - m_fr) < size)
|
||||
if ((m_al - m_fr) < size)
|
||||
{
|
||||
int32_t alloc_ptr = m_al;
|
||||
int32_t alloc_idx = alloc_ptr & (size - 1);
|
||||
|
@ -136,9 +121,9 @@ namespace Lux
|
|||
return NULL;
|
||||
}
|
||||
|
||||
for (; can_read;)
|
||||
while (can_read)
|
||||
{
|
||||
while (m_rd != m_wr)
|
||||
if (m_rd != m_wr)
|
||||
{
|
||||
int cur_read_idx = m_rd;
|
||||
int32_t idx = cur_read_idx & (size - 1);
|
23
src/core/MT/transaction.h
Normal file
23
src/core/MT/transaction.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
#pragma once
|
||||
|
||||
#include "core/MT/event.h"
|
||||
|
||||
namespace Lux
|
||||
{
|
||||
namespace MT
|
||||
{
|
||||
template <class T> struct Transaction
|
||||
{
|
||||
static_assert(std::is_trivially_copyable<T>::value, "T must be trivially copyable!");
|
||||
void setCompleted() { m_event.trigger(); }
|
||||
bool isCompleted() { return m_event.poll(); }
|
||||
void waitForCompletion() { return m_event.wait(); }
|
||||
void reset() { m_event.reset(); }
|
||||
|
||||
Transaction() : m_event(MT::EventFlags::MANUAL_RESET) { }
|
||||
|
||||
MT::Event m_event;
|
||||
T data;
|
||||
};
|
||||
} // ~namespace MT
|
||||
} // ~namespace Lux
|
|
@ -6,11 +6,11 @@
|
|||
|
||||
#define TYPE MULTI_THREAD
|
||||
|
||||
#include "core/MT/lock_free_queue.h"
|
||||
#include "core/MTJD/enums.h"
|
||||
#include "core/MTJD/scheduler.h"
|
||||
#include "core/MT/Task.h"
|
||||
#include "core/MT/transaction_queue.h"
|
||||
#include "core/MT/lock_free_fixed_queue.h"
|
||||
#include "core/MT/task.h"
|
||||
#include "core/MT/transaction.h"
|
||||
#include "core/Array.h"
|
||||
|
||||
namespace Lux
|
||||
|
@ -28,9 +28,9 @@ namespace Lux
|
|||
|
||||
public:
|
||||
|
||||
typedef MT::TransactionQueue<Job*, 512> JobsTable;
|
||||
typedef MT::LockFreeFixedQueue<Job*, 512> JobsTable;
|
||||
typedef MT::Transaction<Job*> JobTrans;
|
||||
typedef MT::TransactionQueue<JobTrans, 32> JobTransQueue;
|
||||
typedef MT::LockFreeFixedQueue<JobTrans, 32> JobTransQueue;
|
||||
typedef Array<JobTrans*> TransTable;
|
||||
|
||||
Manager();
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
|
||||
#include "core/MT/task.h"
|
||||
#include "core/MT/transaction_queue.h"
|
||||
#include "core/MT/lock_free_fixed_queue.h"
|
||||
|
||||
#include "core/MTJD/manager.h"
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ namespace Lux
|
|||
public:
|
||||
FreeList()
|
||||
{
|
||||
m_heap = static_cast<T*>(LUX_NEW_ARRAY(char, sizeof(T) * chunk_size)); // TODO: replace with LUX_ALLOC_T
|
||||
m_heap = static_cast<T*>(LUX_NEW_ARRAY(char, sizeof(T) * chunk_size));
|
||||
m_pool_index = chunk_size;
|
||||
|
||||
for (int32_t i = 0; i < chunk_size; i++)
|
||||
|
|
|
@ -65,21 +65,13 @@ namespace Lux
|
|||
typedef map<const char *, intptr_t, MemTrackAllocator> file_map;
|
||||
typedef map<FileLineReport, uint32_t, MemTrackAllocator> alloc_count_map;
|
||||
|
||||
MemoryTracker* MemoryTracker::s_instance = NULL;
|
||||
#pragma init_seg(compiler)
|
||||
MemoryTracker MemoryTracker::s_instance;
|
||||
uint32_t MemoryTracker::s_alloc_counter = 0;
|
||||
|
||||
MemoryTracker& MemoryTracker::getInstance()
|
||||
{
|
||||
_CrtSetDbgFlag(_CRTDBG_CHECK_DEFAULT_DF); // TODO: pc only
|
||||
s_instance = NULL != s_instance ? s_instance : new(malloc(sizeof(MemoryTracker))) MemoryTracker();
|
||||
return *s_instance;
|
||||
}
|
||||
|
||||
void MemoryTracker::destruct()
|
||||
{
|
||||
s_instance->~MemoryTracker();
|
||||
free(s_instance);
|
||||
s_instance = NULL;
|
||||
return s_instance;
|
||||
}
|
||||
|
||||
void MemoryTracker::add(void* p, const intptr_t size, const char* file, const int line)
|
||||
|
@ -387,35 +379,9 @@ namespace Lux
|
|||
}
|
||||
|
||||
MemoryTracker::~MemoryTracker()
|
||||
{
|
||||
}
|
||||
|
||||
//TODO: PC only
|
||||
// Typedef for the function pointer
|
||||
typedef void (*_PVFV)(void);
|
||||
|
||||
static void LastOnExitFunc()
|
||||
{
|
||||
Lux::MemoryTracker::getInstance().dumpDetailed();
|
||||
Lux::MemoryTracker::destruct();
|
||||
}
|
||||
|
||||
static void CInit()
|
||||
{
|
||||
atexit(&LastOnExitFunc);
|
||||
}
|
||||
|
||||
// Define where our segment names
|
||||
#define SEGMENT_C_INIT ".CRT$XIM"
|
||||
|
||||
// Build our various function tables and insert them into the correct segments.
|
||||
#pragma data_seg(SEGMENT_C_INIT)
|
||||
#pragma data_seg() // Switch back to the default segment
|
||||
|
||||
// Call create our call function pointer arrays and place them in the segments created above
|
||||
#define SEG_ALLOCATE(SEGMENT) __declspec(allocate(SEGMENT))
|
||||
SEG_ALLOCATE(SEGMENT_C_INIT) _PVFV c_init_funcs[] = { &CInit };
|
||||
|
||||
} //~namespace Lux
|
||||
|
||||
#endif //~MEM_TRACK
|
||||
|
|
|
@ -86,7 +86,7 @@ namespace Lux
|
|||
intptr_t m_allocated_memory;
|
||||
uint8_t m_mark;
|
||||
|
||||
static MemoryTracker* s_instance;
|
||||
static MemoryTracker s_instance;
|
||||
static uint32_t s_alloc_counter;
|
||||
};
|
||||
} //~namespace Lux
|
||||
|
|
|
@ -6,9 +6,6 @@ void* operator new (size_t size);
|
|||
void* operator new[] (size_t size);
|
||||
void* operator new (size_t size, size_t alignment);
|
||||
void* operator new[] (size_t size, size_t alignment);
|
||||
//todo: exceptions
|
||||
//void* operator new (size_t size, const std::nothrow_t&);
|
||||
//void* operator new[] (size_t size, const std::nothrow_t&);
|
||||
|
||||
void* operator new (size_t size, const char* file, int line);
|
||||
void* operator new[] (size_t size, const char* file, int line);
|
||||
|
@ -19,9 +16,6 @@ void operator delete (void* p);
|
|||
void operator delete[] (void* p);
|
||||
void operator delete (void* p, size_t alignment);
|
||||
void operator delete[] (void* p, size_t alignment);
|
||||
//todo: exceptions
|
||||
//void operator delete (void* p, const std::nothrow_t&);
|
||||
//void operator delete[](void* p, const std::nothrow_t&);
|
||||
|
||||
void operator delete (void* p, const char* file, int line);
|
||||
void operator delete[] (void* p, const char* file, int line);
|
||||
|
|
|
@ -25,7 +25,6 @@ namespace Lux
|
|||
|
||||
bool OsFile::open(const char* path, Mode mode)
|
||||
{
|
||||
TODO("normalize path");
|
||||
HANDLE hnd = INVALID_HANDLE_VALUE;
|
||||
if(Mode::OPEN & mode)
|
||||
{
|
||||
|
|
|
@ -12,7 +12,7 @@ namespace Lux
|
|||
Queue()
|
||||
{
|
||||
ASSERT(Math::isPowOfTwo(count));
|
||||
m_buffer = (T*)(LUX_NEW_ARRAY(char, sizeof(T) * count)); // TODO: replace with LUX_ALLOC_T
|
||||
m_buffer = (T*)(LUX_NEW_ARRAY(char, sizeof(T) * count));
|
||||
m_wr = m_rd = 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "unit_tests/suite/lux_unit_tests.h"
|
||||
|
||||
#include "core/MT/transaction_queue.h"
|
||||
#include "core/MT/lock_free_fixed_queue.h"
|
||||
#include "core/MT/transaction.h"
|
||||
#include "core/MT/task.h"
|
||||
|
||||
namespace
|
||||
|
@ -13,7 +14,7 @@ namespace
|
|||
};
|
||||
|
||||
typedef Lux::MT::Transaction<Test> AsynTrans;
|
||||
typedef Lux::MT::TransactionQueue<AsynTrans, 16> TransQueue;
|
||||
typedef Lux::MT::LockFreeFixedQueue<AsynTrans, 16> TransQueue;
|
||||
|
||||
class TestTaskConsumer : public Lux::MT::Task
|
||||
{
|
||||
|
|
|
@ -410,7 +410,6 @@ namespace
|
|||
}
|
||||
}
|
||||
|
||||
TODO("string tokenizer");
|
||||
REGISTER_TEST("unit_tests/engine/material_manager", UT_material_manager, "unit_tests/resource_managers/cisla.tga 262188");
|
||||
REGISTER_TEST("unit_tests/engine/material_manager", UT_material_manager, "unit_tests/resource_managers/trava3.dds 2796344");
|
||||
REGISTER_TEST("unit_tests/engine/animation_manager", UT_animation_manager, "unit_tests/resource_managers/blender.ani 3424");
|
||||
|
|
|
@ -1,8 +1,9 @@
|
|||
#include "unit_tests/suite/lux_unit_tests.h"
|
||||
|
||||
#include "core/log.h"
|
||||
#include "core/MT/lock_free_fixed_queue.h"
|
||||
#include "core/MT/task.h"
|
||||
#include "core/MT/transaction_queue.h"
|
||||
#include "core/MT/transaction.h"
|
||||
#include "core/queue.h"
|
||||
#include "core/array.h"
|
||||
|
||||
|
@ -30,7 +31,7 @@ namespace Lux
|
|||
};
|
||||
|
||||
typedef MT::Transaction<UnitTestPair> AsynTest;
|
||||
typedef MT::TransactionQueue<AsynTest, C_MAX_TRANS> TransQueue;
|
||||
typedef MT::LockFreeFixedQueue<AsynTest, C_MAX_TRANS> TransQueue;
|
||||
typedef Queue<AsynTest*, C_MAX_TRANS> InProgressQueue;
|
||||
|
||||
class WorkerTask : public MT::Task
|
||||
|
|
|
@ -55,6 +55,3 @@ namespace Lux
|
|||
namespace { extern "C" Lux::UnitTest::Helper JOIN_STRINGS(JOIN_STRINGS(test_register_, method), __LINE__)(name, method, params); } \
|
||||
LUX_FORCE_SYMBOL(JOIN_STRINGS(test_register_ ,JOIN_STRINGS(method, __LINE__)))
|
||||
|
||||
TODO("Count error messages.");
|
||||
TODO("Count warning messages.");
|
||||
|
||||
|
|
Loading…
Reference in a new issue