|
|
|
@ -48,6 +48,7 @@ |
|
|
|
|
|
|
|
#include <stdio.h> |
|
|
|
|
|
|
|
#include <pthread.h> |
|
|
|
#include <stdlib.h> |
|
|
|
#include <string.h> |
|
|
|
#include <search.h> |
|
|
|
@ -377,6 +378,8 @@ TR_reference(void * mem) |
|
|
|
return mem; |
|
|
|
} |
|
|
|
|
|
|
|
pthread_mutex_t TR_memop_lock = PTHREAD_MUTEX_INITIALIZER; |
|
|
|
|
|
|
|
/* |
|
|
|
* This tries to reflect the memory management behaviour of the |
|
|
|
* GNU version of malloc. For other versions this might need |
|
|
|
@ -435,7 +438,9 @@ TR_malloc(size_t size) |
|
|
|
} |
|
|
|
|
|
|
|
#ifdef MEM_OPT |
|
|
|
pthread_mutex_lock(&TR_memop_lock); |
|
|
|
seg = deleteElement(&segments, size); |
|
|
|
pthread_mutex_unlock(&TR_memop_lock); |
|
|
|
#endif |
|
|
|
|
|
|
|
if (NULL == seg) { |
|
|
|
@ -474,7 +479,9 @@ TR_free(void ** mem) |
|
|
|
seg->ref_count--; |
|
|
|
} else { |
|
|
|
#ifdef MEM_OPT |
|
|
|
pthread_mutex_lock(&TR_memop_lock); |
|
|
|
insertElement(&segments, seg); |
|
|
|
pthread_mutex_unlock(&TR_memop_lock); |
|
|
|
#else |
|
|
|
free(seg); |
|
|
|
#endif |
|
|
|
|