2626 * *
2727 * Author:: Greg Hjelstrom *
2828 * *
29- * $Modtime:: 6/06 /01 11:04a $*
29+ * $Modtime:: 9/26 /01 3:11p $*
3030 * *
31- * $Revision:: 7 $*
31+ * $Revision:: 9 $*
3232 * *
3333 *---------------------------------------------------------------------------------------------*
3434 * Functions: *
5252
5353#include " bittype.h"
5454#include " wwdebug.h"
55+ #include " mutex.h"
56+ #include < new.h>
5557#include < stdlib.h>
5658#include < stddef.h>
5759
@@ -92,6 +94,7 @@ class ObjectPoolClass
9294 uint32 * BlockListHead;
9395 int FreeObjectCount;
9496 int TotalObjectCount;
97+ FastCriticalSectionClass ObjectPoolCS;
9598
9699};
97100
@@ -155,8 +158,7 @@ class AutoPoolClass
155158** the class.
156159*/
157160#define DEFINE_AUTO_POOL (T,BLOCKSIZE ) \
158- ObjectPoolClass<T,BLOCKSIZE> AutoPoolClass<T,BLOCKSIZE>::Allocator
159-
161+ ObjectPoolClass<T,BLOCKSIZE> AutoPoolClass<T,BLOCKSIZE>::Allocator;
160162
161163
162164/* **********************************************************************************************
@@ -274,6 +276,8 @@ void ObjectPoolClass<T,BLOCK_SIZE>::Free_Object(T * obj)
274276template <class T ,int BLOCK_SIZE>
275277T * ObjectPoolClass<T,BLOCK_SIZE>::Allocate_Object_Memory(void )
276278{
279+ FastCriticalSectionClass::LockClass lock (ObjectPoolCS);
280+
277281 if ( FreeListHead == 0 ) {
278282
279283 // No free objects, allocate another block
@@ -296,6 +300,7 @@ T * ObjectPoolClass<T,BLOCK_SIZE>::Allocate_Object_Memory(void)
296300 T * obj = FreeListHead; // Get the next free object
297301 FreeListHead = *(T**)(FreeListHead); // Bump the Head
298302 FreeObjectCount--;
303+
299304 return obj;
300305}
301306
@@ -315,6 +320,8 @@ T * ObjectPoolClass<T,BLOCK_SIZE>::Allocate_Object_Memory(void)
315320template <class T ,int BLOCK_SIZE>
316321void ObjectPoolClass<T,BLOCK_SIZE>::Free_Object_Memory(T * obj)
317322{
323+ FastCriticalSectionClass::LockClass lock (ObjectPoolCS);
324+
318325 WWASSERT (obj != NULL );
319326 *(T**)(obj) = FreeListHead; // Link to the Head
320327 FreeListHead = obj; // Set the Head
0 commit comments