aboutsummaryrefslogtreecommitdiffstats
path: root/src/libstrongswan/utils/leak_detective.c
diff options
context:
space:
mode:
authorTobias Brunner <tobias@strongswan.org>2008-04-03 09:24:35 +0000
committerTobias Brunner <tobias@strongswan.org>2008-04-03 09:24:35 +0000
commit84b18d5fc7ff637eef76e79d2244b98a4a779675 (patch)
tree2883e69f783d363a6ebebea4e3f5891757fd1a93 /src/libstrongswan/utils/leak_detective.c
parent8e91a36314de3c5547705bfe46197b8e0530ee6a (diff)
downloadstrongswan-84b18d5fc7ff637eef76e79d2244b98a4a779675.tar.bz2
strongswan-84b18d5fc7ff637eef76e79d2244b98a4a779675.tar.xz
replaced mutex in leak detective with thread scheduling
Diffstat (limited to 'src/libstrongswan/utils/leak_detective.c')
-rw-r--r--src/libstrongswan/utils/leak_detective.c54
1 files changed, 36 insertions, 18 deletions
diff --git a/src/libstrongswan/utils/leak_detective.c b/src/libstrongswan/utils/leak_detective.c
index e2506e7e2..315e241ab 100644
--- a/src/libstrongswan/utils/leak_detective.c
+++ b/src/libstrongswan/utils/leak_detective.c
@@ -163,12 +163,6 @@ static void *old_malloc_hook, *old_realloc_hook, *old_free_hook;
static bool installed = FALSE;
/**
- * Mutex to exclusivly uninstall hooks, access heap list
- */
-static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
-
-
-/**
* log stack frames queried by backtrace()
* TODO: Dump symbols of static functions. This could be done with
* the addr2line utility or the GNU BFD Library...
@@ -367,8 +361,15 @@ void *malloc_hook(size_t bytes, const void *caller)
{
memory_header_t *hdr;
memory_tail_t *tail;
+ pthread_t thread_id = pthread_self();
+ int oldpolicy;
+ struct sched_param oldparams, params;
+
+ pthread_getschedparam(thread_id, &oldpolicy, &oldparams);
+
+ params.__sched_priority = sched_get_priority_max(SCHED_FIFO);
+ pthread_setschedparam(thread_id, SCHED_FIFO, &params);
- pthread_mutex_lock(&mutex);
count_malloc++;
uninstall_hooks();
hdr = malloc(sizeof(memory_header_t) + bytes + sizeof(memory_tail_t));
@@ -391,7 +392,9 @@ void *malloc_hook(size_t bytes, const void *caller)
}
hdr->previous = &first_header;
first_header.next = hdr;
- pthread_mutex_unlock(&mutex);
+
+ pthread_setschedparam(thread_id, oldpolicy, &oldparams);
+
return hdr + 1;
}
@@ -404,7 +407,10 @@ void free_hook(void *ptr, const void *caller)
int stack_frame_count;
memory_header_t *hdr;
memory_tail_t *tail;
-
+ pthread_t thread_id = pthread_self();
+ int oldpolicy;
+ struct sched_param oldparams, params;
+
/* allow freeing of NULL */
if (ptr == NULL)
{
@@ -413,7 +419,11 @@ void free_hook(void *ptr, const void *caller)
hdr = ptr - sizeof(memory_header_t);
tail = ptr + hdr->bytes;
- pthread_mutex_lock(&mutex);
+ pthread_getschedparam(thread_id, &oldpolicy, &oldparams);
+
+ params.__sched_priority = sched_get_priority_max(SCHED_FIFO);
+ pthread_setschedparam(thread_id, SCHED_FIFO, &params);
+
count_free++;
uninstall_hooks();
if (hdr->magic != MEMORY_HEADER_MAGIC)
@@ -424,7 +434,7 @@ void free_hook(void *ptr, const void *caller)
stack_frame_count = backtrace(stack_frames, STACK_FRAMES_COUNT);
log_stack_frames(stack_frames, stack_frame_count);
install_hooks();
- pthread_mutex_unlock(&mutex);
+ pthread_setschedparam(thread_id, oldpolicy, &params);
return;
}
if (tail->magic != MEMORY_TAIL_MAGIC)
@@ -435,7 +445,7 @@ void free_hook(void *ptr, const void *caller)
stack_frame_count = backtrace(stack_frames, STACK_FRAMES_COUNT);
log_stack_frames(stack_frames, stack_frame_count);
install_hooks();
- pthread_mutex_unlock(&mutex);
+ pthread_setschedparam(thread_id, oldpolicy, &oldparams);
return;
}
@@ -451,7 +461,8 @@ void free_hook(void *ptr, const void *caller)
free(hdr);
install_hooks();
- pthread_mutex_unlock(&mutex);
+
+ pthread_setschedparam(thread_id, oldpolicy, &params);
}
/**
@@ -463,7 +474,10 @@ void *realloc_hook(void *old, size_t bytes, const void *caller)
void *stack_frames[STACK_FRAMES_COUNT];
int stack_frame_count;
memory_tail_t *tail;
-
+ pthread_t thread_id = pthread_self();
+ int oldpolicy;
+ struct sched_param oldparams, params;
+
/* allow reallocation of NULL */
if (old == NULL)
{
@@ -473,7 +487,11 @@ void *realloc_hook(void *old, size_t bytes, const void *caller)
hdr = old - sizeof(memory_header_t);
tail = old + hdr->bytes;
- pthread_mutex_lock(&mutex);
+ pthread_getschedparam(thread_id, &oldpolicy, &oldparams);
+
+ params.__sched_priority = sched_get_priority_max(SCHED_FIFO);
+ pthread_setschedparam(thread_id, SCHED_FIFO, &params);
+
count_realloc++;
uninstall_hooks();
if (hdr->magic != MEMORY_HEADER_MAGIC)
@@ -484,7 +502,7 @@ void *realloc_hook(void *old, size_t bytes, const void *caller)
stack_frame_count = backtrace(stack_frames, STACK_FRAMES_COUNT);
log_stack_frames(stack_frames, stack_frame_count);
install_hooks();
- pthread_mutex_unlock(&mutex);
+ pthread_setschedparam(thread_id, oldpolicy, &oldparams);
raise(SIGKILL);
return NULL;
}
@@ -496,7 +514,7 @@ void *realloc_hook(void *old, size_t bytes, const void *caller)
stack_frame_count = backtrace(stack_frames, STACK_FRAMES_COUNT);
log_stack_frames(stack_frames, stack_frame_count);
install_hooks();
- pthread_mutex_unlock(&mutex);
+ pthread_setschedparam(thread_id, oldpolicy, &oldparams);
raise(SIGKILL);
return NULL;
}
@@ -517,7 +535,7 @@ void *realloc_hook(void *old, size_t bytes, const void *caller)
}
hdr->previous->next = hdr;
install_hooks();
- pthread_mutex_unlock(&mutex);
+ pthread_setschedparam(thread_id, oldpolicy, &oldparams);
return hdr + 1;
}