Lock in ClientMemoryAllocator::Allocate(), and Free().
* Since bitmaps are reference counted, it might not be easy (and already not the case) that holding the ServerApp lock can be enforced. * To be on the safe side, allocations and freeing memory now performs its own locking. * Brought the documentation to the status quo.
This commit is contained in:
@@ -10,18 +10,12 @@
|
|||||||
/*! This class manages a pool of areas for one client. The client is supposed
|
/*! 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.
|
to clone these areas into its own address space to access the data.
|
||||||
This mechanism is only used for bitmaps for far.
|
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;
|
// TODO: areas could be relocated if needed (to be able to resize them)
|
||||||
// locking is not yet done or enforced!
|
// However, this would require a lock whenever a block of memory
|
||||||
|
// allocated by this allocator is accessed.
|
||||||
|
|
||||||
|
|
||||||
#include "ClientMemoryAllocator.h"
|
#include "ClientMemoryAllocator.h"
|
||||||
@@ -29,6 +23,8 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#include <Autolock.h>
|
||||||
|
|
||||||
#include "ServerApp.h"
|
#include "ServerApp.h"
|
||||||
|
|
||||||
|
|
||||||
@@ -38,7 +34,8 @@ typedef chunk_list::Iterator chunk_iterator;
|
|||||||
|
|
||||||
ClientMemoryAllocator::ClientMemoryAllocator(ServerApp* application)
|
ClientMemoryAllocator::ClientMemoryAllocator(ServerApp* application)
|
||||||
:
|
:
|
||||||
fApplication(application)
|
fApplication(application),
|
||||||
|
fLock("client memory lock")
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,6 +66,8 @@ ClientMemoryAllocator::~ClientMemoryAllocator()
|
|||||||
void*
|
void*
|
||||||
ClientMemoryAllocator::Allocate(size_t size, block** _address, bool& newArea)
|
ClientMemoryAllocator::Allocate(size_t size, block** _address, bool& newArea)
|
||||||
{
|
{
|
||||||
|
BAutolock locker(fLock);
|
||||||
|
|
||||||
// Search best matching free block from the list
|
// Search best matching free block from the list
|
||||||
|
|
||||||
block_iterator iterator = fFreeBlocks.GetIterator();
|
block_iterator iterator = fFreeBlocks.GetIterator();
|
||||||
@@ -124,6 +123,8 @@ ClientMemoryAllocator::Free(block* freeBlock)
|
|||||||
if (freeBlock == NULL)
|
if (freeBlock == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
BAutolock locker(fLock);
|
||||||
|
|
||||||
// search for an adjacent free block
|
// search for an adjacent free block
|
||||||
|
|
||||||
block_iterator iterator = fFreeBlocks.GetIterator();
|
block_iterator iterator = fFreeBlocks.GetIterator();
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
#define CLIENT_MEMORY_ALLOCATOR_H
|
#define CLIENT_MEMORY_ALLOCATOR_H
|
||||||
|
|
||||||
|
|
||||||
#include "MultiLocker.h"
|
#include <Locker.h>
|
||||||
|
|
||||||
#include <util/DoublyLinkedList.h>
|
#include <util/DoublyLinkedList.h>
|
||||||
|
|
||||||
@@ -50,6 +50,7 @@ private:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
ServerApp* fApplication;
|
ServerApp* fApplication;
|
||||||
|
BLocker fLock;
|
||||||
chunk_list fChunks;
|
chunk_list fChunks;
|
||||||
block_list fFreeBlocks;
|
block_list fFreeBlocks;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user