diff --git a/src/servers/app/ClientMemoryAllocator.cpp b/src/servers/app/ClientMemoryAllocator.cpp index 99e6c864b8..40410615bf 100644 --- a/src/servers/app/ClientMemoryAllocator.cpp +++ b/src/servers/app/ClientMemoryAllocator.cpp @@ -10,18 +10,12 @@ /*! This class manages a pool of areas for one client. The client is supposed to clone these areas into its own address space to access the data. This mechanism is only used for bitmaps for far. - - Note, this class doesn't provide any real locking - you need to have the - ServerApp locked when interacting with any method of this class. - - The Lock()/Unlock() methods are needed whenever you access a pointer that - lies within an area allocated using this class. This is needed because an - area might be temporarily unavailable or might be relocated at any time. */ -// TODO: right now, areas will always stay static until they are deleted; -// locking is not yet done or enforced! +// TODO: areas could be relocated if needed (to be able to resize them) +// However, this would require a lock whenever a block of memory +// allocated by this allocator is accessed. #include "ClientMemoryAllocator.h" @@ -29,6 +23,8 @@ #include #include +#include + #include "ServerApp.h" @@ -38,7 +34,8 @@ typedef chunk_list::Iterator chunk_iterator; ClientMemoryAllocator::ClientMemoryAllocator(ServerApp* application) : - fApplication(application) + fApplication(application), + fLock("client memory lock") { } @@ -69,6 +66,8 @@ ClientMemoryAllocator::~ClientMemoryAllocator() void* ClientMemoryAllocator::Allocate(size_t size, block** _address, bool& newArea) { + BAutolock locker(fLock); + // Search best matching free block from the list block_iterator iterator = fFreeBlocks.GetIterator(); @@ -124,6 +123,8 @@ ClientMemoryAllocator::Free(block* freeBlock) if (freeBlock == NULL) return; + BAutolock locker(fLock); + // search for an adjacent free block block_iterator iterator = fFreeBlocks.GetIterator(); diff --git a/src/servers/app/ClientMemoryAllocator.h b/src/servers/app/ClientMemoryAllocator.h index 6092b68824..7af6f3a0ef 100644 --- a/src/servers/app/ClientMemoryAllocator.h +++ b/src/servers/app/ClientMemoryAllocator.h @@ -9,7 +9,7 @@ #define CLIENT_MEMORY_ALLOCATOR_H -#include "MultiLocker.h" +#include #include @@ -50,6 +50,7 @@ private: private: ServerApp* fApplication; + BLocker fLock; chunk_list fChunks; block_list fFreeBlocks; }; @@ -77,7 +78,7 @@ public: virtual area_id Area(); virtual uint8* Address(); virtual uint32 AreaOffset(); - + private: ClientMemoryAllocator* fAllocator; block* fBlock;