42-archive/malloc/srcs/interface.c
Jack Halford a28c11d35a done
2017-10-23 19:42:30 +02:00

56 lines
1.6 KiB
C

/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* interface.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/22 13:25:32 by jhalford #+# #+# */
/* Updated: 2017/10/23 19:41:14 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "malloc_internal.h"
t_chunk *g_zones[M_ZONES_MAX] =
{
NULL,
NULL,
NULL,
};
int g_malloc_debug = 1;
pthread_mutex_t g_mutex = PTHREAD_MUTEX_INITIALIZER;
void *malloc(size_t size)
{
void *new_ptr;
pthread_mutex_lock(&g_mutex);
if (g_malloc_debug >= 1)
DGS("malloc called");
new_ptr = ft_malloc(size);
pthread_mutex_unlock(&g_mutex);
return (new_ptr);
}
void free(void *ptr)
{
pthread_mutex_lock(&g_mutex);
if (g_malloc_debug >= 1)
DGS("free called");
ft_free(ptr);
pthread_mutex_unlock(&g_mutex);
return ;
}
void *realloc(void *ptr, size_t size)
{
void *new_ptr;
pthread_mutex_lock(&g_mutex);
if (g_malloc_debug >= 1)
DGS("realloc called");
new_ptr = ft_realloc(ptr, size);
pthread_mutex_unlock(&g_mutex);
return (new_ptr);
}