BBlockCache: Use a pthread_mutex instead of BLocker.
The lighter "struct mutex" is in a private header, so we can't inline it in a public one, so just use pthread_mutex here. By adjusting padding, the class size stays the same (72 bytes on 32-bit, 96 bytes on 64-bit; confirmed via static_assert.) A quick benchmark running "new/delete BMessage" in a loop on 4 threads at once goes from 30-36 seconds before this commit to around 13-17 seconds, sometimes as low as 3 seconds, afterwards, so clearly this is a significant improvement. This also eliminates another BLocker allocated on application startup.
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
#define _BLOCK_CACHE_H
|
||||
|
||||
|
||||
#include <Locker.h>
|
||||
#include <SupportDefs.h>
|
||||
|
||||
|
||||
enum {
|
||||
@@ -31,16 +31,18 @@ private:
|
||||
BBlockCache &operator=(const BBlockCache &);
|
||||
|
||||
private:
|
||||
struct _FreeBlock;
|
||||
struct _FreeBlock;
|
||||
|
||||
_FreeBlock* fFreeList;
|
||||
size_t fBlockSize;
|
||||
int32 fFreeBlocks;
|
||||
int32 fBlockCount;
|
||||
BLocker fLocker;
|
||||
void* (*fAlloc)(size_t size);
|
||||
void (*fFree)(void *pointer);
|
||||
uint32 _reserved[2];
|
||||
_FreeBlock* fFreeList;
|
||||
const size_t fBlockSize;
|
||||
void* (*fAlloc)(size_t size);
|
||||
void (*fFree)(void *pointer);
|
||||
|
||||
pthread_mutex_t fLock;
|
||||
int32 fFreeBlocks;
|
||||
int32 fBlockCount;
|
||||
|
||||
uint32 _reserved[6];
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user