69 lines
No EOL
2 KiB
C
69 lines
No EOL
2 KiB
C
/* ************************************************************************** */
|
|
/* */
|
|
/* ::: :::::::: */
|
|
/* ft_malloc.h :+: :+: :+: */
|
|
/* +:+ +:+ +:+ */
|
|
/* By: thrieg < thrieg@student.42mulhouse.fr> +#+ +:+ +#+ */
|
|
/* +#+#+#+#+#+ +#+ */
|
|
/* Created: 2025/11/17 15:06:51 by thrieg #+# #+# */
|
|
/* Updated: 2025/11/28 17:24:33 by thrieg ### ########.fr */
|
|
/* */
|
|
/* ************************************************************************** */
|
|
|
|
#ifndef FT_MALLOC_H
|
|
#define FT_MALLOC_H
|
|
|
|
#include <stdint.h>
|
|
#include <stdlib.h>
|
|
#include <stdbool.h>
|
|
#include <pthread.h>
|
|
#include <sys/mman.h>
|
|
#include <unistd.h>
|
|
#include <stddef.h>
|
|
#include "../libft/ft_hashmap.h"
|
|
#include "../libft/ft_vector.h"
|
|
#include "ft_malloc_public.h"
|
|
|
|
#define TINY_SIZE_MAX 64
|
|
#define SMALL_SIZE_MAX 4096
|
|
#define ALLIGN_BYTES _Alignof(max_align_t)
|
|
|
|
typedef enum e_type
|
|
{
|
|
E_TINY,
|
|
E_SMALL,
|
|
E_LARGE
|
|
} t_type;
|
|
|
|
typedef struct s_zone
|
|
{
|
|
t_type type;
|
|
size_t size;
|
|
struct s_zone *next; // lock g_mut
|
|
struct s_zone *prev; // lock g_mut
|
|
} t_zone;
|
|
|
|
typedef struct s_header
|
|
{
|
|
size_t size; // lock zone_mut
|
|
bool occupied; // lock zone_mut
|
|
t_zone *zone;
|
|
char padding[8];
|
|
} t_header;
|
|
|
|
typedef struct s_state
|
|
{
|
|
t_zone *tiny_zone; // lock g_mut
|
|
t_zone *small_zone; // lock g_mut
|
|
t_zone *large_zone; // lock g_mut, 1 zone per alloc for large
|
|
} t_state;
|
|
|
|
extern t_state g_state;
|
|
extern pthread_mutex_t g_mut; // never lock this inside a zone mut, only the opposite
|
|
|
|
void *add_large(size_t size);
|
|
void *add_small(size_t size);
|
|
void *add_tiny(size_t size);
|
|
void *add_page(t_type type);
|
|
|
|
#endif |