소스 검색

Added a std::queue with custom allocator

Marko Pintera 12 년 전
부모
커밋
d66d2016cd

+ 6 - 6
CamelotCore/Include/CmCommandQueue.h

@@ -117,12 +117,12 @@ namespace CamelotFramework
 		 * @param	notifyCallback  	Callback that will be called if a command that has "notifyOnComplete" flag set.
 		 * @param	notifyCallback  	Callback that will be called if a command that has "notifyOnComplete" flag set.
 		 * 								The callback will receive "callbackId" of the command.
 		 * 								The callback will receive "callbackId" of the command.
 		 */
 		 */
-		void playback(std::queue<QueuedCommand>* commands, boost::function<void(UINT32)> notifyCallback);
+		void playback(queue<QueuedCommand>::type* commands, boost::function<void(UINT32)> notifyCallback);
 
 
 		/**
 		/**
 		 * @brief	Plays all provided commands. To get the commands call flush().
 		 * @brief	Plays all provided commands. To get the commands call flush().
 		 */
 		 */
-		void playback(std::queue<QueuedCommand>* commands);
+		void playback(queue<QueuedCommand>::type* commands);
 
 
 		/**
 		/**
 		 * @brief	Allows you to set a breakpoint that will trigger when the specified command is executed.
 		 * @brief	Allows you to set a breakpoint that will trigger when the specified command is executed.
@@ -176,7 +176,7 @@ namespace CamelotFramework
 		 * @brief	Returns a copy of all queued commands and makes room for new ones. Must be called from the thread
 		 * @brief	Returns a copy of all queued commands and makes room for new ones. Must be called from the thread
 		 * 			that created the command queue. Returned commands MUST be passed to "playback" method.
 		 * 			that created the command queue. Returned commands MUST be passed to "playback" method.
 		 */
 		 */
-		std::queue<QueuedCommand>* flush();
+		CamelotFramework::queue<QueuedCommand>::type* flush();
 
 
 		/**
 		/**
 		 * @brief	Cancels all currently queued commands.
 		 * @brief	Cancels all currently queued commands.
@@ -192,7 +192,7 @@ namespace CamelotFramework
 		void throwInvalidThreadException(const String& message) const;
 		void throwInvalidThreadException(const String& message) const;
 
 
 	private:
 	private:
-		std::queue<QueuedCommand>* mCommands;
+		CamelotFramework::queue<QueuedCommand>::type* mCommands;
 
 
 		bool mAllowAllThreads;
 		bool mAllowAllThreads;
 		
 		
@@ -299,7 +299,7 @@ namespace CamelotFramework
 		/**
 		/**
 		 * @copydoc CommandQueueBase::flush
 		 * @copydoc CommandQueueBase::flush
 		 */
 		 */
-		std::queue<QueuedCommand>* flush()
+		CamelotFramework::queue<QueuedCommand>::type* flush()
 		{
 		{
 #if CM_DEBUG_MODE
 #if CM_DEBUG_MODE
 #if CM_THREAD_SUPPORT != 0
 #if CM_THREAD_SUPPORT != 0
@@ -309,7 +309,7 @@ namespace CamelotFramework
 #endif
 #endif
 
 
 			lock();
 			lock();
-			std::queue<QueuedCommand>* commands = CommandQueueBase::flush();
+			CamelotFramework::queue<QueuedCommand>::type* commands = CommandQueueBase::flush();
 			unlock();
 			unlock();
 
 
 			return commands;
 			return commands;

+ 1 - 1
CamelotCore/Include/CmDeferredRenderContext.h

@@ -247,7 +247,7 @@ namespace CamelotFramework
 		 */
 		 */
 		void submitToGpu(bool blockUntilComplete = false)
 		void submitToGpu(bool blockUntilComplete = false)
 		{
 		{
-			std::queue<QueuedCommand>* commands = mCommandQueue->flush();
+			queue<QueuedCommand>::type* commands = mCommandQueue->flush();
 
 
 			RenderSystem* rs = RenderSystem::instancePtr();
 			RenderSystem* rs = RenderSystem::instancePtr();
 			rs->queueCommand(boost::bind(&CommandQueueBase::playback, mCommandQueue, commands), blockUntilComplete);
 			rs->queueCommand(boost::bind(&CommandQueueBase::playback, mCommandQueue, commands), blockUntilComplete);

+ 10 - 10
CamelotCore/Source/CmCommandQueue.cpp

@@ -10,7 +10,7 @@ namespace CamelotFramework
 	CommandQueueBase::CommandQueueBase(CM_THREAD_ID_TYPE threadId, bool allowAllThreads)
 	CommandQueueBase::CommandQueueBase(CM_THREAD_ID_TYPE threadId, bool allowAllThreads)
 		:mMyThreadId(threadId), mAllowAllThreads(allowAllThreads), mMaxDebugIdx(0)
 		:mMyThreadId(threadId), mAllowAllThreads(allowAllThreads), mMaxDebugIdx(0)
 	{
 	{
-		mCommands = cm_new<std::queue<QueuedCommand>, PoolAlloc>();
+		mCommands = cm_new<CamelotFramework::queue<QueuedCommand>::type, PoolAlloc>();
 
 
 		{
 		{
 			CM_LOCK_MUTEX(CommandQueueBreakpointMutex);
 			CM_LOCK_MUTEX(CommandQueueBreakpointMutex);
@@ -22,7 +22,7 @@ namespace CamelotFramework
 	CommandQueueBase::CommandQueueBase(CM_THREAD_ID_TYPE threadId, bool allowAllThreads)
 	CommandQueueBase::CommandQueueBase(CM_THREAD_ID_TYPE threadId, bool allowAllThreads)
 		:mMyThreadId(threadId), mAllowAllThreads(allowAllThreads)
 		:mMyThreadId(threadId), mAllowAllThreads(allowAllThreads)
 	{
 	{
-		mCommands = cm_new<std::queue<QueuedCommand>, PoolAlloc>();
+		mCommands = cm_new<CamelotFramework::queue<QueuedCommand>::type, PoolAlloc>();
 	}
 	}
 #endif
 #endif
 
 
@@ -45,7 +45,7 @@ namespace CamelotFramework
 		mCommands->push(newCommand);
 		mCommands->push(newCommand);
 
 
 #if CM_FORCE_SINGLETHREADED_RENDERING
 #if CM_FORCE_SINGLETHREADED_RENDERING
-		std::queue<QueuedCommand>* commands = flush();
+		queue<QueuedCommand>::type* commands = flush();
 		playback(commands);
 		playback(commands);
 #endif
 #endif
 
 
@@ -65,20 +65,20 @@ namespace CamelotFramework
 		mCommands->push(newCommand);
 		mCommands->push(newCommand);
 
 
 #if CM_FORCE_SINGLETHREADED_RENDERING
 #if CM_FORCE_SINGLETHREADED_RENDERING
-		std::queue<QueuedCommand>* commands = flush();
+		queue<QueuedCommand>::type* commands = flush();
 		playback(commands);
 		playback(commands);
 #endif
 #endif
 	}
 	}
 
 
-	std::queue<QueuedCommand>* CommandQueueBase::flush()
+	CamelotFramework::queue<QueuedCommand>::type* CommandQueueBase::flush()
 	{
 	{
-		std::queue<QueuedCommand>* oldCommands = mCommands;
-		mCommands = cm_new<std::queue<QueuedCommand>, PoolAlloc>();
+		CamelotFramework::queue<QueuedCommand>::type* oldCommands = mCommands;
+		mCommands = cm_new<CamelotFramework::queue<QueuedCommand>::type, PoolAlloc>();
 
 
 		return oldCommands;
 		return oldCommands;
 	}
 	}
 
 
-	void CommandQueueBase::playback(std::queue<QueuedCommand>* commands, boost::function<void(UINT32)> notifyCallback)
+	void CommandQueueBase::playback(CamelotFramework::queue<QueuedCommand>::type* commands, boost::function<void(UINT32)> notifyCallback)
 	{
 	{
 #if CM_DEBUG_MODE
 #if CM_DEBUG_MODE
 		RenderSystem* rs = RenderSystem::instancePtr();
 		RenderSystem* rs = RenderSystem::instancePtr();
@@ -121,14 +121,14 @@ namespace CamelotFramework
 		cm_delete<PoolAlloc>(commands);
 		cm_delete<PoolAlloc>(commands);
 	}
 	}
 
 
-	void CommandQueueBase::playback(std::queue<QueuedCommand>* commands)
+	void CommandQueueBase::playback(CamelotFramework::queue<QueuedCommand>::type* commands)
 	{
 	{
 		playback(commands, boost::function<void(UINT32)>());
 		playback(commands, boost::function<void(UINT32)>());
 	}
 	}
 
 
 	void CommandQueueBase::cancelAll()
 	void CommandQueueBase::cancelAll()
 	{
 	{
-		std::queue<QueuedCommand>* commands = flush();
+		CamelotFramework::queue<QueuedCommand>::type* commands = flush();
 		cm_delete<PoolAlloc>(commands);
 		cm_delete<PoolAlloc>(commands);
 	}
 	}
 
 

+ 1 - 1
CamelotCore/Source/CmRenderSystem.cpp

@@ -334,7 +334,7 @@ namespace CamelotFramework {
 		while(true)
 		while(true)
 		{
 		{
 			// Wait until we get some ready commands
 			// Wait until we get some ready commands
-			std::queue<QueuedCommand>* commands = nullptr;
+			queue<QueuedCommand>::type* commands = nullptr;
 			{
 			{
 				CM_LOCK_MUTEX_NAMED(mCommandQueueMutex, lock)
 				CM_LOCK_MUTEX_NAMED(mCommandQueueMutex, lock)
 
 

+ 0 - 3
CamelotUtility/Include/CmMemoryAllocator.h

@@ -270,9 +270,6 @@ namespace CamelotFramework
 	}
 	}
 }
 }
 
 
-#define CM_NEW(T, category) new (CamelotFramework::MemoryAllocator<category>::allocate(sizeof(T)))
-#define CM_DELETE(ptr, T, category) {(ptr)->~T(); CamelotFramework::MemoryAllocator<category>::free(ptr);}
-
 namespace CamelotFramework
 namespace CamelotFramework
 {
 {
 	// Allocators we can use in the standard library
 	// Allocators we can use in the standard library

+ 6 - 0
CamelotUtility/Include/CmStdHeaders.h

@@ -171,6 +171,12 @@ namespace CamelotFramework
 		typedef typename std::stack<T, std::deque<T, A>> type;    
 		typedef typename std::stack<T, std::deque<T, A>> type;    
 	}; 
 	}; 
 
 
+	template <typename T, typename A = StdAlloc<T>> 
+	struct queue
+	{ 
+		typedef typename std::queue<T, std::deque<T, A>> type;    
+	}; 	
+
 	template <typename T, typename P = std::less<T>, typename A = StdAlloc<T>> 
 	template <typename T, typename P = std::less<T>, typename A = StdAlloc<T>> 
 	struct set 
 	struct set 
 	{ 
 	{